Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

The mysql_db_query function executes a query on the specified database and returns a
result identifier. If the link argument is omitted, the last-opened link will be used, or a
new one will be created if necessary.


<?
//connect to server as freetrade user, no password
$dbLink = mysql_pconnect("localhost", "freetrade", "");


//truncate session table
$Query = "DELETE FROM session ";
$dbResult = mysql_db_query("freetrade", $Query, $dbLink);
?>


boolean mysql_drop_db(string database, integer link)


Use mysql_drop_db to delete a database. If the link argument is omitted, the last-
opened link will be used.


<?
//open connection
$dbLink = mysql_connect("localhost", "admin", "secret");


//drop garbage database
if(mysql_drop_db("garbage", $dbLink))
{
print("Database dropped.BR>");
}
else
{
print("Database drop failed!BR>");
}
?>


integer mysql_errno(integer link)


The mysql_errno function returns the error number of the last database action. If the
optional link identifier is left out, the last connection will be assumed.


<?
//connect to server as freetrade user, no password
$dbLink = mysql_pconnect("localhost", "freetrade", "");


//select the 'freetrade' database
mysql_select_db("freetrade", $dbLink);


//try to execute a bad query (missing fields)

Free download pdf