Unit-6
Unit-6
Unit-6
(3151606)
UNIT-6:
DATABASE
CONECTIVITY
USING PHP
❑ MySQL is a database.
❑ A table is a collection of related data entries and it consists of columns and rows.
❑ When deleting a cookie you should assure that the expiration date is in the past.
Ex:
<?php
// set the expiration date to one hour ago
setcookie ("user", "", time()-3600);
?>
CONNECTION TO
SERVER(CRUD EXAMPLE):
❑ mysql_connect() function is used to establish the connection between PHP and
MYSQL.
❑ The mysql_error() function is used to obtain the error messages if any command
gets failed
CLOSING DATABASE:
// some code
mysql_close ($con);
?>
CREATING DATABASE
❑ Ex:
$con=mysql_connect (“servername”, ”sa”, ”shree”);
mysql_query (“CREATE DATABASE student”, $con);
SELECTING DATABASE
❑ Listing Database:
Mysql_list_db($con);
<? php
// Create table
mysql_select_db (“student", $con);
$sql = "CREATE TABLE Student_Data
(
Id int(5),
Name varchar(15),
Age int;
)";
mysql_query($sql,$con); // Execute query
mysql_close($con); //close database
?>
INSERTING DATA:
❑ Ex:
<? Php
mysql_select_db (“student", $con);
$q= ("INSERT INTO Student_Data (Id, Name, Age) VALUES (‘1', ‘XYZ',
‘20')"); mysql_query ($q, $con);
mysql_close ($con);
?>
ALTERING TABLE:
❑ This command is useful to add, delete, changing the size of some columns or
change the name of some column.
❑ Ex:
mysql_select_db (“mydb”, $con);
$query=“Alter Table student add column address varchar(30)”;
mysql_query ($query, $con); // Execution query
mysql_close($con); //closing the database
DROP DATABASE:
❑ Ex:
my_sql_db (“mydb”, $con); //select the database
$query=“DROP DATABASE mydb”;
mysql_query($query,$con);//Execution of query
mysql_close($con); //closing the database
Example(retrieve data from table):
Mysql.php output
Example(update):
output
Mysqlupdate.php
THANK YOU…