Web Development
1
PHP and MYSQL
PHP and MYSQL
Objectives:
At the end of the module the student is expected to:
1. Understand the meaning of MYSQL and its functionalities
2. Understand the application of phpmyadmin.
3. Create php connection script to mysql and close
4. Create web applications that could
a. Pass data
b. Add row
c. Change / update data
d. Delete records
e. Populate data in option list
f. Create a login in page to validate users from the database
PHP Connect to MySQL
PHP 5 and later can work with a MySQL database using:
MySQLi extension (the "i" stands for improved)
PDO (PHP Data Objects)
Open a Connection to MySQL
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Course Module
Close the Connection
The connection will be closed automatically when the script ends. To
close the connection before, use the following:
$conn->close();
Connecting to database
Web Development
3
PHP and MYSQL
Course Module
Passing data
Web Development
5
PHP and MYSQL
Course Module
Adding row
Web Development
7
PHP and MYSQL
Course Module
Web Development
9
PHP and MYSQL
Deleting rows
Course Module
Web Development
11
PHP and MYSQL
Changing data
Course Module
Web Development
13
PHP and MYSQL
Course Module
Populate option list
Web Development
15
PHP and MYSQL
Login validation
Course Module
Web Development
17
PHP and MYSQL
References
Murach, J. (2014) Murach’s PHP and MYSQL (2nd Edition)
Yank, K, PHP and MYSQL: Novice to Ninja
WEBSITE
http://php.net/
http://www.w3schools.com/php/
https://www.tutorialspoint.com/php/
Course Module