Connect php to mysql and obtain data. How to solve this problem-php Tutorial

Source: Internet
Author: User
Connect php to mysql and obtain data. How does php determine whether a piece of data exists in the mysql database ?? Find the code instance. Mysqlphp database connects php to mysql and obtains data.
How does php determine whether a piece of data exists in the mysql database ?? Find the code instance.

Mysql php database instance

Share:


------ Solution --------------------


$ Conn = mysql_connect ("localhost", "root", ""); // connection statement, server, user name, password
Mysql_select_db ("test", $ conn); // connect to the local test database
Mysql_query ("set names gbk"); // SET it to Chinese
$ A = mysql_query ("select * from stu_info"); // select the stu_info table in the test database.
While ($ row = mysql_fetch_row ($ a) // read data when the table data is not empty
Echo "name:". $ row [0]. "Gender:". $ row [1]. "age:". $ row [2]."
";
?>

------ Solution --------------------
$ Result = mysql_query ("select * from table where id = xx ");
$ Num = mysql_num_rows ($ result );
If ($ num> 0 ){
Print_r (mysql_fetch_assoc ($ result ));
}

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.