Blog Details

PHP: The Complete Beginner's Guide

  Larch Soft

1. What is PHP?

PHP stands for Hypertext Preprocessor. PHP is a popular and widely-used open source server-side scripting language, which is used to manage the dynamic content of the website. PHP was created by Rasmus Lerdorf in 1994. It was initially known as Personal Home Page. PHP files typically have a .php extension.

It is embedded within HTML code and executed on the server before sending the output to the client's web browser. PHP can be integrated with popular databases like MySQL, PostgreSQL, Oracle, Microsoft SQL Server, Sybase etc.

PHP is faster than other scripting languages, for example, ASP and JSP.


2. PHP Features

Performance: PHP script is executed much faster than other languages such as JSP and ASP. PHP uses its own memory, so the server loading time and workload is automatically reduced, which results in better performance and faster processing speed.

Familiarity with syntax: PHP has easily understandable syntax. Programmers are comfortable coding with it.

Open Source: PHP source code and software are freely available on the web. You can develop all the versions of PHP according to your requirement without paying any cost. All its components are free to download and use.

Embedded: PHP code can be easily embedded within HTML tags and script.

Database Support: PHP supports all the leading databases such as MySQL, SQLite, ODBC, Oracle, etc.

Error Reporting: PHP has predefined error reporting constants to generate an error notice or warning at runtime. E.g., E_ERROR, E_WARNING, E_STRICT, E_PARSE.

Web servers Support: PHP is compatible with almost all local servers used today like Apache, Netscape, Microsoft IIS, etc.

Security: PHP is a secure language to develop the website. It consists of multiple layers of security to prevent threads and malicious attacks.

Control: Different programming languages require long script or code, whereas PHP can do the same work in a few lines of code. It has maximum control over the websites like you can make changes easily whenever you want.

PHP Beginner's Guide

3. Setting Up PHP

Install a web server (e.g., Apache) on your computer or use a local development environment like XAMPP or WAMP, which include PHP and MySQL.

Configure the server to recognize PHP files and execute them properly.


4. Setting Up XAMPP

XAMPP is a free and open-source tool used by web developers in the Windows family and other platforms to set up the development and testing environment. XAMPP server comes with the XAMPP control panel to manage all its components easily.
XAMPP stands for (X) Cross-platform, (A) Apache, (M) MySQL, (P) PHP, (P) Perl and with some additional modules including phpmyadmin (for the database), FileZilla, Mercury, and Tomcat.
Once you have installed and configured the XAMPP server in your system, you can easily work with any CMS like WordPress, Joomla, drupal and more. XAMPP server works like a local server in your system that is generally used by PHP developers to test the websites (web-projects).


Installation Of XAMPP for Windows

Step 1: To download the XAMPP server, visit the "" website in your web browser.

Step 2: Click on "XAMPP for Windows". Then, navigate the downloading location and the file will be automatically downloaded.

Step 3: Double-click the downloaded file to launch the XAMPP installer.

Step 4: "Setup" window will appear on the screen. Then, click on the "Next" button.

Step 5: Select the components that you want to install and click on the "Next" button.


Step 6: Choose a folder to install the XAMPP and click on the "Next" button.

Step 7: "Ready to Install" window will appear on the screen, then click on the "Next" button.

Step 8: Click on the "Finish" button.

5. Basics Of PHP

  • PHP code is enclosed within <?php and ?> tags.
  • PHP statements end with a semicolon (;).
  • Use the echo statement to display content on the web page.
    Example: <?php echo "Hello, World!"; ?>
  • Variables are used to store and manipulate data.
    Start variable names with a dollar sign ($).
    Example: $name = "Rooster";
  • PHP supports various data types, including strings, integers, floating-point numbers, booleans, arrays, and objects.
  • PHP supports arithmetic, assignment, comparison, logical, and other types of operators.
  • PHP arrays are used to store multiple values in a single variable.


6. Connect the Database

     $host = 'localhost:3306';  
     $user = '';  
     $pass = '';  
     $conn = mysqli_connect($host, $user, $pass);

     if(! $conn )  {  
           die('Could not connect: ' . mysqli_error());  
     echo 'Connected successfully';  


7. Commands in MySql Database

  • SELECT - extracts data from a database
  • UPDATE - updates data in a database
  • DELETE - deletes data from a database
  • INSERT INTO - inserts new data into a database
  • CREATE DATABASE - creates a new database
  • ALTER DATABASE - modifies a database
  • CREATE TABLE - creates a new table
  • ALTER TABLE - modifies a table
  • DROP TABLE - deletes a table


8. Time in PHP

       echo "The date is " . date("Y/m/d") . "</br>";
       echo "The time is " . date("h:i:sa") . "</br>";
       echo "Today is " . date("l");

Output :

The date is 2023/06/10
The time is 05:40:24am
Today is Saturday