MySQL tutorial _db_query and mysql_query query difference
Mysql_db_query
/*
Mysql_db_query syntax: int mysql_db_query (string database, string query, int [link_identifier]);
The Mysql_db_query function is used to send out query strings (queries) to the MySQL database tutorial in the backend. But the omitted parameter Link_identifier if does not exist, the program will automatically look for other mysql_connect () The connection code after the connection. Returns False when an error occurs
*/
$server = ' www.111cn.net ';
if (! $link = mysql_connect ($server, ' mysql_user ', ' Mysql_password ')) {
Echo ' could not connect to http://www.111cn.net MySQL ';
Exit
}
Else
{
$query = mysql_db_query (' db ', $sql, $link);
if ($query)
{
while ($row = Mysql_fetch_assoc ($query)) {
echo $row [' foo '];
}
Mysql_free_result ($query);
}
Else
{
echo "DB Error, could not query the Databasen";
Echo ' MySQL Error: '. Mysql_error ();
Exit
}
}
Let's take a look at the Mysql_query function instance
Mysql_query
$CN = mysql_connect ($server, ' root ', ' root ');
mysql_select_db (' db ', $CN); We use mysql_db_query here, don't set it.
$result = mysql_query ($sql);
while ($rs = Mysql_fetch_array ($result))
{
echo $row [' foo '];
}
Mysql_free_result ($result);
/*
This site original tutorial reproduced annotated source PHP tutorial er/php.html ">http://www.111cn.net/phper/php.html
*/
?>