Web Technologies
Web Technologies
Got it! Let’s cover all the PHP and MySQL topics from your syllabus one by one in a clear,
easy-to-remember, exam-ready format. I’ll present it in a way that helps you quickly revise
and also write confidently in your exam.
Example:
php
<?php
echo "Hello, World!"; // Output: Hello, World!
?>
require Same as include, but causes error if file not found require "config.php";
1/14
2. Connecting to MySQL Server
php
<?php
$conn = mysqli_connect("localhost", "root", "", "mydatabase");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully!";
?>
3. Creating a Database
php
4. Selecting a Database
php
php
2/14
echo $row[0] . "<br>";
}
php
7. Creating a Table
php
php
9. Altering Tables
Add a new column:
php
php
3/14
ALTER TABLE users MODIFY name VARCHAR(200);
php
php
php
php
14. phpMyAdmin
4/14
Can be used to:
Insert/edit/delete data
Export/import data
🟨 Next Up:
Managing State – the next major section includes:
Cookies
Sessions
Serialization
HTTP is stateless → once a page is loaded, the server forgets the user unless we use
state management techniques.
5/14
Each HTTP request is independent.
If a user logs in and goes to another page, the server “forgets” the login info unless we
manually track it.
Solution: Use mechanisms to maintain state between pages (like sessions, cookies,
query strings, etc.).
Query strings are added to the end of a URL using ? and &.
Format: ?key=value&key2=value2
Example:
⟶ URL: http://example.com/profile.php?name=Alice&age=20
Access in PHP:
php
<?php
$name = $_GET['name']; // "Alice"
$age = $_GET['age']; // "20"
?>
Use Case:
Useful for small data like search terms, filters, or simple navigation.
Example:
URL: http://example.com/user/Alice
With URL rewriting, PHP might receive the name via $_GET or a route.
Note: This technique is more advanced and not as common in basic PHP exams.
3. Cookies
6/14
Cookies store small pieces of data on the user's browser.
php
Get a cookie:
php
echo $_COOKIE["username"];
Delete a cookie:
php
Use Case:
4. Sessions
Sessions store user data on the server, unlike cookies which store it on the client.
Start a session:
php
session_start();
$_SESSION["username"] = "Alice";
php
7/14
session_start();
echo $_SESSION["username"];
Destroy session:
php
session_start();
session_unset(); // Unset session variables
session_destroy(); // Destroy session
Use Case:
5. Serialization
Commonly used when storing complex data structures like arrays or objects.
Serialize an array:
php
Unserialize:
8/14
php
$restoredArray = unserialize($serializedData);
Use Case:
🎯 Exam Tip:
Use cookies when you want to store small data on the browser (like "remember me").
Use sessions when you need secure and temporary storage (like login).
Would you like a quick one-page final revision sheet with the most important code and
points from both sections?
9/14
Awesome! Here's your final 1-page Quick Revision Sheet for PHP, MySQL & State
Management (for exam writing):
php
2. Create a Database
php
4. Show Databases
php
5. Show Tables
php
6. Create Table
php
10/14
7. Insert Data
php
8. Select Data
php
9. Alter Table
php
php
php
12. phpMyAdmin
Common Errors:
Wrong credentials
11/14
Syntax errors
php
$name = $_GET['name'];
2. Cookies
Set:
php
Get:
php
echo $_COOKIE["username"];
Delete:
php
3. Sessions
Start:
php
12/14
session_start();
$_SESSION["username"] = "Alice";
Access:
php
echo $_SESSION["username"];
Destroy:
php
session_unset();
session_destroy();
4. Serialization
Convert array to string:
php
$serial = serialize($arr);
Back to array:
php
$arr = unserialize($serial);
13/14
Feature Cookies Sessions
php
Print:
echo "Hello";
Superglobals:
$_GET, $_POST, $_SESSION, $_COOKIE
Include file:
include("header.php");
Good luck on your exam! If you’d like I can quiz you with some short or long questions now
for practice. Would you like a practice round?
14/14