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'; }
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.