0% found this document useful (0 votes)
4 views22 pages

XAMPP: Local PHP Development Guide

XAMPP is a free software package that creates a local server environment for running PHP applications, including components like Apache, MySQL/MariaDB, and phpMyAdmin. It allows developers to test websites offline and simulate production environments. The document also covers database servers, character sets, collations, and SQL commands related to case sensitivity and sorting.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views22 pages

XAMPP: Local PHP Development Guide

XAMPP is a free software package that creates a local server environment for running PHP applications, including components like Apache, MySQL/MariaDB, and phpMyAdmin. It allows developers to test websites offline and simulate production environments. The document also covers database servers, character sets, collations, and SQL commands related to case sensitivity and sorting.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

XAMPP is a free and open-source software package that provides a local server

environment to run PHP-based web applications on your own computer.

🧩 Full Form:

XAMPP stands for:

 X = Cross-platform (Windows, Linux, macOS)


 A = Apache (Web server)
 M = MySQL / MariaDB (Database)
 P = PHP (Programming language)
 P = Perl (Optional scripting language)

🚀 What XAMPP Includes:

 Apache: The web server that serves your PHP files.


 MySQL/MariaDB: The database system for storing application data.
 PHP: Server-side scripting language used in web development.
 phpMyAdmin: Web interface to manage MySQL databases.
 FileZilla FTP Server, Mercury Mail Server, and Tomcat (optional tools).

Why Use XAMPP?

 Develop and test websites locally without needing an internet connection.


 Run CMS platforms like WordPress, Joomla, and Drupal on your computer.
 Easily simulate a production-like environment before uploading your site to a live
server.

MySQL/MariaDB is also a server, specifically a database server.

✅ Here's how it works:

 Apache is a web server: It handles HTTP requests and serves web pages.
 MySQL/MariaDB is a database server: It stores, manages, and serves data when
your application (via PHP) requests it.

📌 What's a Database Server?

A database server is a program that:

 Listens for database queries (requests for data),


 Processes them (like adding, retrieving, or deleting data), and
 Sends back the results.
For example, when a user logs into a website:

1. PHP sends a request to MySQL server to find the user info.


2. MySQL fetches it from the database and returns it.
3. PHP processes it and shows it on the web page.

🔄 MySQL vs MariaDB:

 Both are relational database servers.


 MariaDB is a drop-in replacement for MySQL, created by the original MySQL
developers.
 XAMPP uses MariaDB now (instead of MySQL) by default, but they function
similarly.

You can replace MySQL with MariaDB without changing your application code — it
will still work the same way.

🧩 In Detail:

 Same commands: SQL queries (like SELECT, INSERT, UPDATE) work the same.
 Same connectors: PHP, Python, Java etc. can connect to MariaDB using the same
MySQL drivers.
 Same file formats: MariaDB uses the same database files and structure as MySQL.
 Same user interface: Tools like phpMyAdmin work the same way with both.

What is a Database Server?

A Database Server is a software (and sometimes hardware) system that stores, manages,
and serves data to other programs or users over a network.

In the context of SQL, a database refers to a structured collection of


organized information, or data, typically stored electronically within a
computer system. These databases are designed to efficiently store,
manage, and retrieve large volumes of data.

id INT(3)

It can be confusing — so let’s clarify:

✅ What it means:

INT is the data type — it means the column will store integers.
The (3) is display width, not the size or range of the number.

❌ Common Misunderstanding:

INT(3) does NOT mean the number can only go up to 999 or is limited to 3 digits.

✅ Truth:

An INT can still store values from -2,147,483,648 to +2,147,483,647 regardless of the number in
parentheses.

🟡 When does the (3) matter?

The number in parentheses (e.g. INT(3)) used to affect display width only when used with ZEROFILL:

id INT(3) ZEROFILL

This would display:

1 as 001

25 as 025

But this is just formatting — not limiting the value stored.

1. Use a Case-Sensitive Collation

Example:

SELECT * FROM users

WHERE name COLLATE utf8mb4_bin = 'John';

This will match only 'John' — not 'john', 'JOHN', or 'JoHn'.

Common Case-Sensitive Collations:

Charset Case-Sensitive Collation


utf8 utf8_bin

utf8mb4 utf8mb4_bin

latin1 latin1_bin

2. Change Column Collation (Permanent Solution)

To make all future queries case-sensitive for a column:

ALTER TABLE users

MODIFY name VARCHAR(100)

COLLATE utf8mb4_bin;

This makes the name column case-sensitive for all queries using =.

3. Force Case Sensitivity Temporarily

If you don’t want to alter the table, use BINARY keyword:

SELECT * FROM users

WHERE BINARY name = 'John';

Matches exactly 'John',

Doesn't match 'john' or 'JOHN'.

4. Check Current Collation of a Column

SHOW FULL COLUMNS FROM users;

Look under the Collation column.

Notes:

utf8_general_ci and utf8mb4_general_ci are case-insensitive

utf8_bin and utf8mb4_bin are case-sensitive

Using BINARY is the simplest for one-time case-sensitive comparisons


latin1_swedish_ci — What It Means in MySQL

latin1_swedish_ci is a collation in MySQL. Let's break it down:

Meaning of Each Part:

Part Meaning

latin1 The character set (also called encoding), supports Western European characters.

swedish The locale (language) rules used for sorting and comparing characters.

ci Case-insensitive — 'a' = 'A' in comparisons.

Why "Swedish"?

MySQL's original developers were Swedish, and so latin1_swedish_ci became the default collation
for latin1.

It doesn't mean your data is Swedish — it's just using Swedish sorting/comparison rules for the
latin1 character set.

Example Behavior:

If a column has latin1_swedish_ci collation:

SELECT * FROM users WHERE name = 'JOHN';

It will match rows where name is:

'JOHN'

'john'

'John'

'JoHn'
Because it’s case-insensitive (ci).

Should I Use It Today?

Not recommended for modern applications:

It's limited to Western European characters (not good for multilingual data).

Use utf8mb4 instead (supports all Unicode characters, including emojis and Asian scripts).

Recommended Alternative:

CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci

Or even:

CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

Summary:

Term Means

latin1 Western European character set

swedish Swedish language sorting rules

ci Case-insensitive comparisons

latin1_swedish_ci MySQL’s default collation (older)

What Is a Character Set in MySQL (or General Computing)?

A character set (or charset) is a collection of characters and the rules that assign each character a
unique number (code) so it can be stored and processed by computers.

In Simple Terms:

A character set defines what characters you can store (like letters, numbers, symbols) and how they
are stored in bytes.
Examples of Character Sets:

Character Set Description

latin1 Western European characters only (like English, French, Spanish)

utf8 Supports many languages, but only partial Unicode (up to 3 bytes)

utf8mb4 Full Unicode support (up to 4 bytes), includes emojis

ascii Basic 128 characters (A–Z, a–z, 0–9, symbols)

Example:

The letter A has:

ASCII value of 65

In UTF-8, also stored as 65

In UTF-16, stored as two bytes: 00 41

How It's Used in MySQL:

When you create a table or column, you can assign a character set like:

CREATE TABLE users (

name VARCHAR(100)

) CHARACTER SET utf8mb4;

This means the name column can store characters from many languages, including emojis and
special symbols.

Difference Between Charset and Collation

Term Meaning

Character Set What characters can be stored (and how they're stored in bytes)

Collation How characters are compared and sorted (case-sensitive? locale?)


How to Check Character Set of a Column

SHOW FULL COLUMNS FROM users;

Or for a database:

SELECT DEFAULT_CHARACTER_SET_NAME

FROM information_schema.SCHEMATA

WHERE schema_name = 'your_database';

you can make MySQL case-sensitive, either:

Globally

Per database

Per table

Per column

Per query

1. Make a Column Case-Sensitive

Change the column's collation to a case-sensitive one, like utf8mb4_bin or utf8_bin.

ALTER TABLE users

MODIFY name VARCHAR(100)

CHARACTER SET utf8mb4

COLLATE utf8mb4_bin;
Now, SELECT * FROM users WHERE name = 'John';

will NOT match 'john' or 'JOHN'.

🔧 2. Make a Table Case-Sensitive

If all text columns should be case-sensitive, define collation at the table level:

CREATE TABLE users (

name VARCHAR(100)

) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

3. Make a Database Case-Sensitive

Set a case-sensitive collation when creating a database:

CREATE DATABASE mydb

CHARACTER SET utf8mb4

COLLATE utf8mb4_bin;

Existing tables must still use a case-sensitive collation explicitly — this only sets the default for new
tables.

4. Force Case Sensitivity in a Query (Temporary)

You can force case sensitivity without changing any schema by using:

SELECT * FROM users WHERE BINARY name = 'John';

or

SELECT * FROM users WHERE name COLLATE utf8mb4_bin = 'John';

5. Server-Level Case Sensitivity for Table Names (Linux Only)

On Linux, table names are case-sensitive by default because of the file system.
To control this:

Edit [Link] or [Link]:

[mysqld]

lower_case_table_names=0

0 = Case-sensitive (Linux)

1 = Case-insensitive (Windows default)

Changing this requires a MySQL restart and can cause issues with existing table names.

Summary Table

Scope How to Enable Case Sensitivity

Column Use COLLATE utf8mb4_bin on that column

Table Set table's default collation to *_bin

Database Create database with *_bin collation

Query Use BINARY or COLLATE in WHERE clause

Global FS lower_case_table_names=0 on Linux only

Summary

Concept Example

Character Set utf8mb4, latin1

Defines What characters can be stored and how

Stores Letters, symbols, emojis, etc.

Used in MySQL, HTML, programming languages

ORDER BY in MySQL

The ORDER BY clause is used to sort the result set of a query by one or more columns.
✅ Basic Syntax

SELECT column1, column2

FROM table_name

ORDER BY column1 [ASC|DESC], column2 [ASC|DESC];

ASC = Ascending order (default)

DESC = Descending order

🔍 Examples

1. Sort by a Single Column (Ascending)

SELECT * FROM users

ORDER BY name;

Sorts users alphabetically by name.

2. Sort by a Single Column (Descending)

SELECT * FROM users

ORDER BY created_at DESC;

Shows the most recent rows first.

3. Sort by Multiple Columns

sql

Copy

Edit

SELECT * FROM products

ORDER BY category ASC, price DESC;

Sorts by category first, then by highest price within each category.

4. Sort by a Calculated Column


sql

Copy

Edit

SELECT name, salary, bonus, (salary + bonus) AS total_income

FROM employees

ORDER BY total_income DESC;

🔍 Case-Sensitive Sort (if collation is case-sensitive)

sql

Copy

Edit

SELECT * FROM users

ORDER BY name COLLATE utf8mb4_bin;

Sorts considering A ≠ a if your collation supports it.

📌 Important Notes

If you don’t use ORDER BY, MySQL may return rows in any order (even if it looks sorted, it’s not
guaranteed).

ORDER BY comes after WHERE and GROUP BY, but before LIMIT in a query.

🧠 Tip: Reverse Order with DESC

sql

Copy

Edit

SELECT * FROM orders

ORDER BY order_date DESC

LIMIT 5;

Top 5 most recent orders.

Let me know if you need:


ORDER BY with JOIN

ORDER BY with NULL values first or last

Sorting by LENGTH, LOWER(), or custom logic

You said:

use case

ChatGPT said:

✅ Use Case of ORDER BY in MySQL

Here are real-world use cases where you'd use ORDER BY to sort your query results meaningfully:

1. 🔍 Customer List Sorted Alphabetically

sql

Copy

Edit

SELECT customer_id, name, email

FROM customers

ORDER BY name ASC;

Use case: Display a customer list in A–Z order in a UI.

2. 📅 Latest Orders First


sql

Copy

Edit

SELECT order_id, customer_id, order_date, total_amount

FROM orders

ORDER BY order_date DESC;

Use case: Show the most recent orders at the top of an admin dashboard.

3. 💰 Top-Selling Products

sql

Copy

Edit

SELECT product_id, product_name, total_sales

FROM products

ORDER BY total_sales DESC

LIMIT 10;

Use case: Display top 10 best-selling products on an e-commerce homepage.

4. 🧾 Invoices Sorted by Amount Due

sql

Copy

Edit

SELECT invoice_id, client_id, due_date, total_amount

FROM invoices

WHERE status = 'PENDING'

ORDER BY total_amount DESC;

Use case: Show pending invoices with the highest amounts at the top for quick review.

5. 🧑‍💼 Employees by Department and Salary

sql

Copy
Edit

SELECT name, department, salary

FROM employees

ORDER BY department ASC, salary DESC;

Use case: Group employees by department and show highest paid first in each.

6. 🔠 Case-Sensitive Sort (e.g., 'Apple' before 'apple')

sql

Copy

Edit

SELECT name

FROM users

ORDER BY name COLLATE utf8mb4_bin;

Use case: Alphabetical sorting where uppercase letters come before lowercase (if collation allows).

🧠 Bonus: Sorting by String Length

sql

Copy

Edit

SELECT name

FROM products

ORDER BY LENGTH(name);

Use case: Find products with the shortest/longest names.

Example: Customers & Orders

sql

Copy

Edit

-- Create Customers table (parent table)

CREATE TABLE customers (

customer_id INT AUTO_INCREMENT PRIMARY KEY,


customer_name VARCHAR(100) NOT NULL

);

-- Create Orders table (child table) with foreign key referencing customers table

CREATE TABLE orders (

order_id INT AUTO_INCREMENT PRIMARY KEY,

order_date DATE NOT NULL,

customer_id INT,

FOREIGN KEY (customer_id) REFERENCES customers(customer_id)

ON UPDATE CASCADE

ON DELETE CASCADE

);

How It Works:

FOREIGN KEY (customer_id) → defines the link between the orders.customer_id and
customers.customer_id.

ON UPDATE CASCADE → if a customer_id changes in the parent table, it will update in orders
automatically.

ON DELETE CASCADE → if a customer is deleted, all their orders will also be deleted.

Insert and Test:

sql

Copy

Edit

-- Insert into customers

INSERT INTO customers (customer_name) VALUES ('John Doe'), ('Jane Smith');

-- Insert into orders

INSERT INTO orders (order_date, customer_id) VALUES ('2025-08-11', 1), ('2025-08-12', 2);

-- Try deleting a customer (this will delete their orders too because of ON DELETE CASCADE)
DELETE FROM customers WHERE customer_id = 1;

If you want, I can also show you an example with multiple foreign keys linking three tables.

-- Customers table (Parent #1)

CREATE TABLE customers (

customer_id INT AUTO_INCREMENT PRIMARY KEY,

customer_name VARCHAR(100) NOT NULL

);

-- Orders table (Child of Customers, Parent of Order Items)

CREATE TABLE orders (

order_id INT AUTO_INCREMENT PRIMARY KEY,

order_date DATE NOT NULL,

customer_id INT,

FOREIGN KEY (customer_id) REFERENCES customers(customer_id)

ON UPDATE CASCADE

ON DELETE CASCADE

);

-- Products table (Parent #2)

CREATE TABLE products (

product_id INT AUTO_INCREMENT PRIMARY KEY,

product_name VARCHAR(100) NOT NULL,


price DECIMAL(10,2) NOT NULL

);

-- Order Items table (Child of Orders and Products)

CREATE TABLE order_items (

order_item_id INT AUTO_INCREMENT PRIMARY KEY,

order_id INT,

product_id INT,

quantity INT NOT NULL,

FOREIGN KEY (order_id) REFERENCES orders(order_id)

ON UPDATE CASCADE

ON DELETE CASCADE,

FOREIGN KEY (product_id) REFERENCES products(product_id)

ON UPDATE CASCADE

ON DELETE RESTRICT

);

How Relationships Work

orders.customer_id → customers.customer_id`

Links each order to the customer who placed it.

order_items.order_id → orders.order_id`

Links each order item to a specific order.

order_items.product_id → products.product_id`

Links each order item to a specific product.

-- Add customers

INSERT INTO customers (customer_name) VALUES ('John Doe'), ('Jane Smith');

-- Add products

INSERT INTO products (product_name, price) VALUES


('Laptop', 850.00),

('Mouse', 25.00),

('Keyboard', 45.00);

-- Add orders

INSERT INTO orders (order_date, customer_id) VALUES

('2025-08-11', 1),

('2025-08-12', 2);

-- Add order items

INSERT INTO order_items (order_id, product_id, quantity) VALUES

(1, 1, 1), -- Order 1, Laptop

(1, 2, 2), -- Order 1, 2 Mice

(2, 3, 1); -- Order 2, Keyboard

If you delete a customer, all their orders and related order_items will be deleted automatically
(cascade).

If you try to delete a product that is still used in order_items, MySQL will block it because of ON
DELETE RESTRICT.

1. ANY (or SOME)

 ANY and SOME are the same thing (aliases).


 Compares a value to each row of a subquery and returns TRUE if the condition is
satisfied by at least one row.

✅ Example:

-- Find employees who earn more than ANY (at least one) employee in
department 10
SELECT *
FROM employees
WHERE salary > ANY (SELECT salary FROM employees WHERE department_id = 10);

👉 Returns employees whose salary is greater than the lowest salary in dept 10.

🔹 2. ALL

 Returns TRUE if the condition is satisfied by all rows in the subquery.


 Usually used with =, >, <, >=, <=.
✅ Example:

-- Find employees who earn more than ALL employees in department 10


SELECT *
FROM employees
WHERE salary > ALL (SELECT salary FROM employees WHERE department_id = 10);

👉 Returns employees whose salary is greater than the highest salary in dept 10.

🔹 3. EXISTS

 Returns TRUE if the subquery returns at least one row.


 Often used to check existence rather than values.

✅ Example:

-- Find departments that have at least one employee


SELECT d.department_id, d.department_name
FROM departments d
WHERE EXISTS (SELECT 1 FROM employees e WHERE e.department_id =
d.department_id);

👉 Returns only departments with employees.

🔹 4. Comparison
Operator Meaning Example (salary compared to subquery)

True if condition holds for at least one salary > ANY(subquery) → salary >
ANY / SOME
row minimum

salary > ALL(subquery) → salary >


ALL True if condition holds for every row
maximum

EXISTS True if subquery returns any row EXISTS(subquery) → at least one row exists

🔹 5. Real-World Scenario

Suppose you want:

 ANY/SOME → "Find products priced higher than at least one competitor's product."
 ALL → "Find products priced higher than every competitor's product."
 EXISTS → "Find customers who have placed at least one order."

👉 So:
 ANY / SOME = at least one row
 ALL = every row
 EXISTS = whether rows exist at all

Suppose we have this employees table:

emp_id name department salary


1 Alice HR 3000
2 Bob HR 4000
3 Charlie IT 6000
4 Diana IT 8000

🔹 Now, compare IT salaries (6000, 8000) against HR salaries (3000, 4000).

Query Meaning Result


salary > ANY (SELECT salary FROM Salary > at least one HR IT: 6000 ✅, 8000 ✅
employees WHERE department = 'HR') salary (min HR = 3000) → Both pass
salary > ALL (SELECT salary FROM Salary > all HR salaries IT: 6000 ✅, 8000 ✅
employees WHERE department = 'HR') (max HR = 4000) → Both pass
salary < ANY (SELECT salary FROM Salary < at least one HR IT: 6000 ❌, 8000 ❌
employees WHERE department = 'HR') salary → None pass
salary < ALL (SELECT salary FROM Salary < all HR salaries IT: 6000 ❌, 8000 ❌
employees WHERE department = 'HR') (min HR = 3000) → None pass
EXISTS (SELECT 1 FROM employees
WHERE department = 'HR') True if HR has employees ✅ (HR exists)

✅ Summary Table

Operator Logic Example with IT salaries vs HR (3000, 4000)


ANY / SOME Compare with at least one value > ANY (3000, 4000) → > 3000
ALL Compare with all values > ALL (3000, 4000) → > 4000
EXISTS True if subquery returns rows HR has employees → TRUE

👉 Rule of thumb:

 ANY → compares with minimum (when using >).


 ALL → compares with maximum (when using >).
 EXISTS → just checks if rows exist.

What is the ANSI SQL Standard?

 ANSI = American National Standards Institute.


 In 1986, ANSI (and later ISO in 1987) defined a standard version of SQL called
SQL-86 (or SQL-87 in ISO).
 The goal: make SQL portable across different RDBMS vendors (Oracle, MySQL,
SQL Server, PostgreSQL, DB2, etc.).

👉 Without a standard, every vendor would have a completely different SQL language.

You might also like