PHP Chapter 5
PHP Chapter 5
PHP Chapter 5
Unit - V
• Now click the ‘Edit Privilidges’ under ‘Actions’ option for the username ‘root’
and Hostname ‘localhost’.
• Now choose the third tab ‘Change password’ and type your password in the
provided field, retype the password to confirm it and then finally click on the
‘Go’ key to conclude the process.
Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
7
MHSSP
5.1 Introduction to MySQL
• Set password to phpMyAdmin:
• MySQL was the main extension that was designed to help PHP
applications send and receive data from MySQL database.
• PDO (PHP Data Objects): the main advantage of using PDO is that it
supports, and provides a uniform method of access to 11 different
databases.
• However PDO doesn’t allow the usage of all features available in present
version of the MySQL server.
Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
10
MHSSP
5.2 Connecting to a MySQL Database
• MySQL : MySQLi : PDO
Parameters MySQL MySQLi PDO
Connection $connection_link = $mysqli_db = new mysqli('host', $pdo = new PDO('mysql:host=host;
mysql_connect("host", "username", 'username', 'password', dbname=database_name;
"password"); 'database_name'); charset=utf8',
'username', 'password');
mysql_select_db("database_name",
$connection_link);
mysql_set_charset('UTF-8',
$connection_link);
Error Error handling in MySQL is not Error handling in MySQLi is a bit PDO has the best error handling
Handling considered to be a good approach. easier. methods. It also provides error
modes for error handling
Data Fetching General programming loops such as Same as MySQL, code however will PDO provides many built-in
for, or while can be used in MySQL. be a bit different. statements: fetchAll(),
fetchColumn() etc.
API support MySQL provides a ProceduralPrepared
way. By: Khan
MySQLi provides
Mohammed both
Zaid, Lecturer, Procedural
Comp. Engg., as PDO provides an Object Oriented
11
well as MHSSP
Object Oriented way approach
Functions to fetch data from Database
• mysqli_fetch_row()
• mysqli_fetch_assoc()
• mysqli_fetch_array()
• mysqli_fetch_object()
• mysqli_fetch_lengths()
• mysqli_fetch_field()
• This function will fetch data about the single row with which the row pointer
currently exists.
• After fetching the entire row details, it will be returned as an array with
number indices corresponding to the MySQL field offset.
• If no results found for the query, then mysqli_fetch_row() will return NULL.
• This MySQL fetch method returns resultant array with both indices.
• That is, field offset and field name. So, it would be used most probably by
having both option of indexing.
echo $row->user_name;
• It returns an array of integer that represents the size of each column or FALSE
if fails.
• Parameter:
Result: It specifies the result set identifier returned by mysqli_query(),
mysqli_store_result() or mysqli_use_result()
• Returns the definition of one column of a result set as an object. Call this
function repeatedly to retrieve information about all columns in the result set.
Login.php Login_process.php
Insert.html Register_process.php
Login table