Simple PHP MySql instance for addition, deletion, modification, and query, and phpmysql instance for addition and Deletion
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 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 echo in the row "</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 ); // close 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);?>
The simple example of the above PHP MySql addition, deletion, modification, and query is all the content shared by the editor. I hope to give you a reference and support for the help house.