Lec # 23 PHP - VI
Lec # 23 PHP - VI
Lecture 23
MySQL Basics
(PHP - VI)
1
INTRODUCTION
• In order to have really full featured
application. We are going to need to
incorporate a database.
CRUD
Create, Read, Update, Delete
• UPDATE table
SET id = ‘7’, name=‘abc’
WHERE id = 1;
SQL DELETE (Delete)
• Format:
• http://localhost/phpmyadmin
Using PHPMyAdmin
• It enables you to access your MySQL database
through a GUI. You can easily do the following:
Selects a database to
use.
• mysqli_num_rows(result variable from query);
Execute database
query
Return number of
rows, after execution
of query
• mysqli_fetch_array(“result variable from query”);
Used to return several
rows of the entire
results of a database
• mysqli_fetch_assoc(“result variable
queryfrom query”)
• md5(string);
• x33cz33433434xx
It uses is to encrypt a
string. It returns 32
characters
hexadecimal number
md5()
• Example:
$str = “Hello”;
echo md5($str);
• Output:
8bla9953c4611296a827abf8c47804d7
date()
• Example:
echo date(“Y”); // 2015 (year)
echo date(“m”); // 12 (month)
echo date(“d”); // 27 (day)
echo date(“Y-m-d”); // 2015-01-27
echo date(“d/m/y”); // 28/12/15
echo date(“F d, Y”); // January 28, 2015
echo date(“F j, Y, h:i:s a”);
// September 28, 2015, 12:12:35 AM
STEP 1
• <?php
// 1. Create a database connection
$connection = mysqli_connect(“localhost”, “root”,
“password”, “database name”););
if (!$connection) {
die(“Database connection failed: ” . mysqli_error());
}
?>
<html>
…
</html>
this function returns a value, that will stored in $connection.
That value is called handle.
STEP 1: Connection Code
<?php
$connection =
mysqli_connect("localhost","root","","dbdeptse");
// Check connection
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}else{
echo "Connected successfully";
}
?>
STEP 2
• <?php
// 1. Create a database connection
$connection = mysqli_connect(“localhost”, “root”, “password”);
if(!$connection) {
die(“Database connection failed: ” . mysql_error());
}