PHP Mysql KVR
PHP Mysql KVR
By
Rama Satish K V
Asst. Professor, RNSIT
www.google.com/+ramasatishkv
PHP for Database Access
Connect to the MySQL server
$connection = mysql_connect("localhost",
$username, $password);
Access the database
mysql_select_db("winestore", $connection);
Perform SQL operations
Disconnect from the server
mysql_close($connection);
Prof. Rama Satish K V, Asst. Professor, RNSIT, Bengaluru
Error Handling
All mysql_ functions return NULL (or
false) if they fail.
Several functions are helpful in graceful
failure
die(string) - halts and displays the string
mysql_errno() - returns number of error
mysql_error() - returns text of error
function showerror()
{
die("Error " . mysql_errno() . " : " . mysql_error());
}
if (!(mysql_select_db("winestor", $connection)))
showerror();