Programming in PHP Notes
Subject Overview
Programming in PHP covers PHP fundamentals and control structures, functions/
Subject at a glance
4
Units
30
Topics
5
Credits
4
Infographics
Unit-wise Syllabus
4 units — open any unit for detailed topic-wise notes, diagrams and important exam questions
- Evolution of PHP
- PHP scripting basics
- receiving user input
- PHP data types
- operators
- variable manipulation and scope
- control structures (if/elseif, switch, while, do-while, for loops, nesting)
- 1Browser requests page.php
- 2Web server passes it to the PHP engine
- 3PHP runs the script
May query MySQL
- 4Output is plain HTML
- 5Browser displays the HTML
Study guide
PHP is a server-side scripting language for dynamic websites. You study its evolution, scripting basics, receiving user input, data types, operators, variable manipulation and scope and control structures (if-elseif, switch, while, do-while, for, nesting). Run every small script on a local server to see the output.
- Function definition/creation/return values
- user-defined and dynamic functions
- default arguments
- string formatting/comparison/matching
- index-based and associative arrays
- array looping with each() and foreach()
Keys
Numbers from 0
Named strings
Example
$a = ["red", "blue"];
$a = ["name" => "Ana"];
Access
$a[0]
$a["name"]
Loop
for or foreach
foreach ($a as $k => $v)
Study guide
You study functions (definition, return values, user-defined and dynamic functions, default arguments), string formatting, comparison and matching, and arrays: indexed and associative, with looping through foreach. Practise array and string functions; they are used in almost every PHP program.
- Working with forms and superglobal variables
- importing and accessing user input
- opening/copying/renaming/deleting files
- working with directories
- generating images with PHP
- MySQL database connectivity
- DML operations (insert, delete, update, select)
- joins (cross, inner, outer, self)
INNER JOIN
Only matching rows in both tables
Orders with their customers
LEFT JOIN
All left rows, plus matches
Customers even without orders
CROSS JOIN
Every combination of rows
Generating all pairs
SELF JOIN
A table joined to itself
Employees and their managers
Study guide
You study forms and superglobals, importing user input, file operations (open, copy, rename, delete), directories, generating images, MySQL connectivity, insert, delete, update and select operations and joins. Build a small form-to-database application end to end.
- Setting and deleting cookies
- session creation and destruction
- encoding/decoding session variables
- FTP/SMTP server introduction
- math functions
- file upload/download
- email with PHP
- error tackling and debugging
- PHP project requirements analysis
Stored on
The browser
The server
Security
Less: user can see and edit
More secure
Size
Small (about 4 KB)
Larger
Lifetime
Until its expiry date
Until the browser closes or timeout
Study guide
You study cookies, sessions, encoding and decoding session variables, FTP and SMTP basics, math functions, file upload and download, sending email, error handling and debugging and the requirements analysis for a PHP project. Use sessions to build a simple login system.
Why Programming in PHP Matters
PHP and MySQL power a very large share of websites, including WordPress, so PHP skills lead directly to web development and freelance work.
How to Prepare for Programming in PHP
- Build a small database-driven project such as a login system or blog.
- Always validate and sanitise user input.
- Learn the difference between GET and POST and between cookies and sessions.
Programming in PHP: Frequently Asked Questions
What is the difference between cookies and sessions?
Cookies store small data in the user's browser, while sessions store data on the server and identify the user with a session ID.
Which database is commonly used with PHP?
MySQL is the most common database used with PHP.
