Simple instance for adding, deleting, modifying, and querying in PHPMySql; Tutorial for adding and deleting instances in phpmysql _ PHP

Source: Internet
Author: User
Tags php mysql
Simple instance for adding, deleting, modifying, and querying in PHPMySql, and adding and deleting instances in phpmysql. PHPMySql adds, deletes, modifies, and queries simple instances. phpmysql adds and deletes instances mysql_connect () connects to the database mysql_select_db and selects the database mysql_fetch_assoc () to obtain the result set mysql_query () for simple instances that execute SQL statements for adding, added or deleted instances in phpmysql

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 SQL statement echo"
 
 
  
  
"; While ($ row = mysql_fetch_assoc ($ userInfo) // obtain the data of each row in the result set {echo"
  
  
     "; Echo" 
    "; Echo" 
    "; Echo" 
    "; Echo" 
   ";} Echo" 
  
"; Echo $ row ['id']; // obtain the id echo in the row""; Echo $ row ['username']; echo""; Echo $ row ['password']; echo"
"; 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.

Http://www.bkjia.com/PHPjc/1136618.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1136618.htmlTechArticlePHP MySql add delete modify query simple instance, phpmysql add delete instance mysql_connect () connection database mysql_select_db select database mysql_fetch_assoc () get results set mysql_query () execute SQL...

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.