PHP & MySQL¶
Learn server-side programming and database management.
Quick Start¶
New to PHP? Start here:
- Laracasts: PHP for Beginners (2023) - Complete video series
- Laracasts: OOP Principles in PHP (2024) - Object-oriented programming
- PHP 8 Tutorial - Interactive tutorials
Database:
- Laracasts: MySQL Database Design - Video series
- MySQL Tutorial - PHP + MySQL integration
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
Core Learning¶
PHP Fundamentals¶
- PHP Language Reference - Official documentation
- PHP Tutorial (TutorialsPoint) - Comprehensive guide
- PHP Namespaces - Code organization
- PHP Cheatsheet - Quick reference
Best Practices¶
- Clean Code PHP - Write maintainable code
MySQL¶
- MySQL Tutorial (TutorialsPoint) - Complete database guide
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¶
Goal: Score 70% or higher