<3> Select a database function (1):
mysql_select_db ()
Format: int mysql_select_db (string database name, int link_identifier);
Returns 1 false values if the specified database name is selected, succeeds, returns 1 Truth (True), and fails.
Example 1:
<?php
$select = mysql_select_db (' forum ', $connect);
if ($select)
{echo "Connect db forum successed!";}
Else
{echo "Connect db forum failed!";}
?>
Example 2:
<?php
$select = mysql_select_db ("forum", $connect) or Die ("Can not connect this db!");
?>
Note: This function is equivalent to the USE statement in MySQL: Use forum
<4>. SQL query Functions (2):
1, mysql_query ()
Format: int mysql_query (string sqlquery, int link_identifier);
Send a standard SQL statement request to the server. If it fails, a false value is returned.
Example:
<?php
$connect = mysql_connect ($hostname, $user, $pwd);
$select = mysql_select_db ($dbname, $connect);
$query = mysql_query ($sql, $connect);
if ($query) echo "Successed!";
else echo "Failed!";
?>
This function must be used in conjunction with the mysql_select_db () function, it is meaningless to use it alone!
2, Mysql_db_query ()
Format: int mysql_db_query (String database, string sqlquery, int link_identifier);
Database names and SQL statement sqlquery must be specified in this function, and False if failed.
Example:
<?php
$connect = mysql_connect ($hostname, $user, $pwd);
$query = Mysql_db_query ($dbname, $sql, $connect);
if ($query) echo "Successed!";
else echo "Failed!";
?>
The difference between mysql_db_query () and mysql_query () is that the former can select database databases without using mysql_select_db (), while the SQL statement is executed while the database is selected.