Skip to main content
PHP for Beginners
CHAPTER 31 Beginner

Bonus: PHP Quick Reference

Updated: May 12, 2026
15 min read

# BONUS SECTIONS: PHP Quick Reference

1. PHP Glossary

  • Array: A variable that holds multiple values.
  • Composer: A dependency manager for PHP to easily install third-party libraries.
  • CRUD: Create, Read, Update, Delete. The four basic database operations.
  • Framework: A pre-built structure of code (like Laravel or Symfony) that speeds up development.
  • Hash: A one-way mathematical function used to secure passwords.
  • MVC: Model-View-Controller. An architectural design pattern that separates data logic, UI, and business logic.
  • Object: An instance of a Class in Object-Oriented Programming.
  • PDO: PHP Data Objects. The modern, secure way to connect PHP to databases.
  • Superglobal: Built-in PHP arrays (like $_POST, $_SESSION) available anywhere in a script.
  • XSS: Cross-Site Scripting. A vulnerability where hackers inject malicious JavaScript.

---

2. PHP Cheat Sheet

Variables & Output

php
123
$name = "Alice";
echo "Hello " . $name;
var_dump($name); // Debugging

Arrays

php
1234
// Indexed
$colors = ["Red", "Blue"];
// Associative
$user = ["name" => "Alice", "role" => "Admin"];

Loops

php
123
foreach ($user as $key => $value) {
    echo "$key : $value";
}

Functions

php
123
function add($a, $b = 0) {
    return $a + $b;
}

Database (PDO)

php
1234
$pdo = new PDO("mysql:host=localhost;dbname=test", "root", "");
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id");
$stmt->execute([':id' => 1]);
$user = $stmt->fetch();

---

3. Common PHP Errors Guide

1. Parse error: syntax error, unexpected 'echo' *Cause:* You forgot a semicolon ; on the line exactly *before* the echo.

2. Fatal error: Uncaught Error: Call to undefined function myFunction() *Cause:* You misspelled the function name, or forgot to require the file where the function is defined.

3. Warning: Cannot modify header information - headers already sent *Cause:* You tried to use header(), session_start(), or setcookie(), but you already outputted HTML or text to the browser. Check for empty lines before your opening <?php tag.

4. Notice: Undefined index: username *Cause:* You are trying to access $_POST['username'] or an array key that doesn't exist. Always wrap array accesses in isset().

---

4. PHP Interview Prep

Q: Explain the difference between require and include. *A:* require halts the script with a Fatal Error if the file is missing. include throws a Warning but allows the script to continue running.

Q: How do you prevent SQL Injection? *A:* By using Prepared Statements via PDO or MySQLi. Prepared statements separate the SQL logic from the user-provided data, preventing malicious code from executing.

Q: What is a Session and how does it differ from a Cookie? *A:* A Session stores data on the server and is destroyed when the browser closes. A Cookie stores data on the user's local browser and has a specific expiration date.

Q: Explain MVC. *A:* Model-View-Controller is an architectural pattern. The Model handles database logic. The View handles HTML rendering. The Controller handles incoming requests, fetches data from the Model, and passes it to the View.

---

5. PHP Developer Roadmap

  1. 1. Basics: Syntax, Variables, Loops, Functions.
  1. 2. Intermediate: Forms, Sessions, Cookies, File Handling.
  1. 3. Database: SQL basics, PDO, Prepared Statements, CRUD operations.
  1. 4. Advanced PHP: Object-Oriented Programming (Classes, Inheritance, Interfaces).
  1. 5. Security: Hashing, XSS, CSRF, SQLi prevention.
  1. 6. Architecture: Namespaces, Composer, MVC Pattern.
  1. 7. Frameworks: Learn Laravel or Symfony.
  1. 8. APIs: Building REST APIs, outputting JSON.

---

6. Beginner Backend Roadmap

  1. 1. Internet Basics: How HTTP, DNS, and Browsers work.
  1. 2. Frontend Basics: HTML, CSS, Vanilla JavaScript.
  1. 3. Backend Language: PHP (or Node.js / Python).
  1. 4. Databases: Relational Databases (MySQL, PostgreSQL).
  1. 5. Version Control: Git & GitHub.
  1. 6. Hosting: cPanel, Linux Basics, SSH.
  1. 7. APIs: RESTful architecture, Postman.
  1. 8. Caching & Scaling: Redis, Memcached, Load Balancing.

---

7. Hostinger & cPanel Deployment Guide

Deploying your PHP site to a shared host like Hostinger is exciting! Here is a beginner's checklist.

1. Uploading Files via File Manager

  1. 1. Log in to your Hostinger dashboard.
  1. 2. Navigate to File Manager.
  1. 3. Open the public_html folder. This is the root of your live website.
  1. 4. Drag and drop your .php files and folders here.
*Pro-tip: If you have many files, zip them on your computer, upload the .zip to public_html, and use the Extract tool.*

2. Setting Up the Database

  1. 1. Go to MySQL Databases in your hosting control panel.
  1. 2. Create a new Database Name (e.g., u123_myapp).
  1. 3. Create a new Database Username (e.g., u123_user) and a highly secure password.
  1. 4. Click Create/Add User to Database and grant "All Privileges".

3. Using phpMyAdmin

  1. 1. Go to phpMyAdmin in your control panel.
  1. 2. Select your newly created database.
  1. 3. If you have a .sql export file from your local XAMPP, click the Import tab and upload it to recreate your tables instantly.

4. Updating Configuration (.env or config.php)

Your local XAMPP used root and an empty password. Your live site does not!
  1. 1. Open your db.php or config.php file in the Hostinger File Manager.
  1. 2. Update the credentials using the database name, username, and password you just created in Step 2.
$pdo = new PDO("mysql:host=localhost;dbname=u123_myapp", "u123_user", "SecurePass123!"); *(Note: 'localhost' usually stays the same because the database and the files are on the same server).*

5. Domain and SSL Basics

  • Domain: Ensure your domain name's Nameservers point to your host (e.g., ns1.hostinger.com). This can take up to 24 hours to propagate across the internet.
  • SSL (HTTPS): Hostinger provides free Let's Encrypt SSL certificates. Find the SSL section in your dashboard and click "Install". This ensures your site loads over secure https:// and avoids the browser "Not Secure" warning.

Congratulations! Your PHP application is now live for the world to see!

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·