Skip to content

PHP & MySQL

Learn server-side programming and database management.

Quick Start

New to PHP? Start here:

Database:

Required Tools Setup

Install these before starting: - Composer - PHP dependency manager (Download) - Laravel Herd - Local PHP development environment (Download) - MySQL or MariaDB - Database server

Database Tools (choose one):

  • PHPMyAdmin - Web-based database management
  • TablePlus - Modern database GUI (Mac/Windows/Linux)
  • MySQL Workbench - Official MySQL tool
  • Sequel Ace - Mac-only database management
# Check installations
php --version
composer --version
mysql --version

Core Learning

PHP Fundamentals

Best Practices

MySQL

Practice Problems

Problem 1: Debug the Log Function 🐛

Bug: This code doesn't write to the file. Find the issue!

<?php
function writeLog($message) {
    $file = fopen('log.txt', 'r');  // ⚠️ Bug here!
    fwrite($file, $message . PHP_EOL);
    fclose($file);
}

writeLog('This is a test log.');
?>
💡 Hint Check the file mode in fopen(). What does 'r' do vs what you need?

Problem 2: Fix Email Validation 🔍

Bug: Empty emails pass validation. We need to check if the key exists, but allow empty values.

<?php
$data = array(
    'user' => array(
        'name'  => 'Alice',
        'email' => '',  // Empty but key exists
    ),
);

// This should pass since key exists
if (!empty($data['user']['email'])) {  // ⚠️ Bug here!
    echo 'Email key is provided.' . "\n";
} else {
    echo 'Email key is missing.' . "\n";
}
?>
💡 Hint Use isset() to check if a key exists, regardless of its value.

🤔 Deep Dive Topics

Master these PHP concepts:

  • Type Juggling - How PHP handles type conversions
  • Session Management - session_start(), $_SESSION, session_destroy()
  • PDO vs mysqli - Database abstraction vs MySQL-specific
  • Regular Expressions - preg_match(), preg_replace(), preg_split()
  • Error Handling - try/catch, throw, custom exceptions
  • Autoloading - PSR-4, Composer autoloader

Test Your Knowledge

Take the PHP & MySQL Quiz →

Goal: Score 70% or higher