Learning from mistakes

Wow my dad wont be proud of me, i did one post and got two wrongs straights :slightly_smiling_face:

3 Likes

It happens. Don’t get discouraged. One rule that I usually follow is to never post code without testing it. Especially code targeting new developers. Get comfortable with creating tiny little test projects. The time spent will help in your normal work as well.

4 Likes

Thanks alot, but i wasn’t even bordered, let alone getting discouraged.
Discouragement comes when you start percieving yourself as experts when you practically knew nothing.

Am a proud novice!

But sitepoint is really helping me improve, so typing codes non tested will always result to error, am using my phone in most cases to type. So wont see error until Apache yells at me, then i start to look for patch up.
Am just here to learn and improve

  1. Don’t use your phone
  2. Learn how to run php from a console
  3. Learn to use the php development server

point me to number two and three, i really want to learn using a console, what it is all about? And whats php development server? Is it localhost?

@riversiderocks thanks but i have gone through the link you sent. And i cant find any element that start the program.

Can just type those codes in my browser to access the server?
Is no difference from xamp or mamp or laragon?

With Laragon or Xampp, you dont need to use the built in Php server.

Thanks @benanamen
Suppose i want to use the inbuilt php server what should i do? Or is it that my windows operating system has an inbuilt php server that i can start like every other application on my laptop?
Or php.net provides a url for testing purposes.
How do i get started?

Secondly, what is console? I have heard that alot

You need to be able to open what is called a console window. It is a place where you can type commands and see the results. The details depend very much on your operating system. I’m guessing you use windows which is unfortunate but still workable.

From a console window, enter:

php --version

This will run the php executable and show you the current php version. php is nothing more than a program. If you get something like “unknown command” then it means you will need to dig in and figure out how to set your PATH variable. Again, it is all operating system dependent.

Once the version command is running then make yourself a file called HelloWorld.php and insert:

<?php
error_reporting(E_ALL);
echo "Hello World\n";

From the command line, enter:

php HelloWorld.php

And you should see the Hello World output. Congratulations. You have just ran a php file from the console window.

It may not seem like much but you can do quite a bit of testing and development this way without the constant browser refreshing that you probably currently do. You can test all your bootstrap code, sql queries and quite a bit of other stuff. If you use an IDE such as PHPStorm then you can even use buttons to run this sort of stuff without ever leaving the IDE.

Shifting gears a bit, we can use another php command to run a development server so we don’t need to bother with any of the xamp nonsense during development.

php -S localhost:8000
[Sat Aug 29 07:27:22 2020] PHP 7.4.7 Development Server
 (http://localhost:8000) started

Open a browser and enter: http://localhost:8000/HelloWorld.php in the address bar. You should see Hello World in your browser. You will also see some useful information in the console window. And that is really all there is to it. You can browse through your app without xampp. You still need a server when you deploy your app in production but no real need for one when developing.

2 Likes

This is detailed, and i thank you alot for it but i must report you to windows for calling their product “unfortunate”

Anyways am ready to start practicing but i only have two questions

  1. Is console what we call command prompt in windows? If it is, then it often ask me of path to a php .exe file to run with, but if is different then how do I locate it in my windows system.

  2. Who will borrow me mysql database to run some sql query and see result in the console, and can i actually add data and pull data from the mysql in the console?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.