Mysql_db_query and mysql_query Query differences

Source: Internet
Author: User

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
*/
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.