php connect mysql database and query record all records

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags closed connect echo host mysql mysql database mysql tutorial network

Here is a simple PHP database operation procedures, we are talking about php connect mysql database, and then execute the sql query and then we want the records displayed, and finally closed And mysql database connection.
* /
$ host = 'localhost';
$ user_name = 'root';
$ password = 'admin';

$ conn = mysql_connect ($ host, $ user_name, $ password);
if (! $ conn)
{
die ('database connection failed:' .mysql_error ());
}
Echo 'database connection is successful! Continue to operate ... ';

mysql_select_db ('test');

$ sql = 'select id, name, city from users';
$ result = mysql_query ($ sql);

if ($ result)
{
echo 'sql statement:'. $ sql. 'has been successfully executed! ';
$ num = mysql_num_rows ($ result); // Call the function mysql_num_row () to get the number of rows in the select statement's query result
echo 'The sql query to <b>'. $ num. '</ b> www.jzread.com Line data';
}

if (mysql_close ($ conn))
{
echo '........';
echo 'to the database connection has been successfully closed';
}

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.