Simple PHP MySql instance for addition, deletion, modification, and query, and phpmysql instance for addition and Deletion

Source: Internet
Author: User

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.

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.