PHP MySql addition, deletion, modification, and query
Mysql_connect () connecting to the database
Mysql_select_db select database
Mysql_fetch_assoc () to obtain the result set
Mysql_query () Execute SQL statements
Example:
<? Php
$ Con = @ mysql_connect ('localhost', 'root', 'root'); // connect to the database
Mysql_select_db ('test', $ con); // select a database
$ UserInfo = mysql_query ("select * from user", $ con); // create an SQL statement
Echo "<table> ";
While ($ row = mysql_fetch_assoc ($ userInfo) // obtain the data of each row in the result set
{
Echo "<tr> ";
Echo "<td> ";
Echo $ row ['id']; // obtain the id in the row
Echo "</td> ";
Echo "<td> ";
Echo $ row ['username'];
Echo "</td> ";
Echo "<td> ";
Echo $ row ['Password'];
Echo "</td> ";
Echo "</tr> ";
}
Echo "</table> ";
Mysql_free_result ($ userInfo); // release the result set
Mysql_close ($ con); // closes the database
/* Delete
$ D = @ mysql_connect ('localhost', 'root', 'root ');
Mysql_select_db ('test', $ d );
Mysql_query ("delete from user where id = 1", $ d );
Mysql_close ($ d );
*/
/* Insert
$ I = @ mysql_connect ('localhost', 'root', 'root ');
Mysql_select_db ('test', $ I );
Mysql_query ("insert into user (username, password) values ('ad', 'ad')", $ I );
Mysql_close ($ I );
*/
// Update
$ U = @ mysql_connect ('localhost', 'root', 'root ');
Mysql_select_db ('test', $ u );
Mysql_query ("update user set username = 'aaa' where username = '00'", $ u );
Echo "update user set username = 'ax 'where id = 2 ";
Mysql_close ($ u );
?>
Thank you for your support!
You can contact me. Renhanlinbsl@163.com
Technorati labels: PHP, Mysql, add, delete, modify, and query