PHP queries the complete MySQL database code
PHP queries the complete MySQL database code. When using this code, you must modify the user name and password in the connection statement.
<? Php
$ Link = mysql_connect ('localhost', 'root', '000000') // The following prompt is displayed: Change the user name and password first.
Or die ('could not connect: '. mysql_error ());
Mysql_select_db ('ruida ') or die ('could not select database ');
// Execute SQL query
$ Query = 'select * FROM product ';
$ Result = mysql_query ($ query) or die ('query failed: '. mysql_error ());
// Display the result in HTML
Echo "<table> \ n ";
While ($ line = mysql_fetch_assoc ($ result )){
Echo "\ t <tr> \ n ";
Foreach ($ line as $ col_value ){
Echo "\ t <td> $ col_value </td> \ n ";
}
Echo "\ t </tr> \ n ";
}
Echo "</table> \ n ";
// Release the result set
Mysql_free_result ($ result );
// Close the connection to Liehuo. Org
Mysql_close ($ link );
?>