Differences between mysql_db_query and mysql_query

Source: Internet
Author: User
Tags mysql tutorial

I don't want to talk about the difference. I can see the above instance. I mainly want to know the difference between mysql_select_db and I don't recommend using this function since PHP 4.0.6 in terms of performance. Do not use this function. Replace it with mysql_select_db () and mysql_query ().

What is the difference between mysql tutorial _ db_query and mysql_query?

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 a query string to the backend MySQL database. If the parameter link_identifier that can be omitted does not exist, the program will automatically find the connection code after other mysql_connect () connections. If an error occurs, false is returned.

*/

$ Server = 'www. bKjia. c0m ';

If (! $ Link = mysql_connect ($ server, 'mysql _ user', 'mysql _ password ')){
Echo 'could not connect to http://www.bKjia. c0m 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, cocould 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. Do not set it here.
$ Result = mysql_query ($ SQL );
While ($ rs = mysql_fetch_array ($ result ))
{
Echo $ row ['foo'];
}
Mysql_free_result ($ result );
/*

I don't want to talk about the difference. I can see the above instance. I mainly want to know the difference between mysql_select_db and I don't recommend using this function since PHP 4.0.6 in terms of performance. Do not use this function. Replace it with mysql_select_db () and mysql_query ().

This site original tutorials reprinted Indicate source php tutorial er/php.html "> http://www.bKjia. c0m/phper/php.html
*/
?>

Related Article

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.