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 ));
}