Summary of basic php mysql operations

Source: Internet
Author: User
Tags php and mysql php mysql mysql index

Occasionally, you need to use php to perform some mysql Database Operation tests. It is too troublesome to write by yourself. The search results generally contain a lot of useless code. Here we will summarize the operations of php mysql, I hope you don't have to worry about it in the future.

<? Php $ dbhost = 'localhost'; $ dbuser = 'root'; $ dbpass = '000000'; $ dbname = 'products'; $ connect = mysql_connect ($ dbhost, $ dbuser, $ dbpass); if (! $ Connect) exit ('database connection failed! '); Mysql_select_db ($ dbname, $ connect); mysql_query ('set names utf8'); // query $ SQL = "SELECT * FROM 'category '"; $ result = mysql_query ($ SQL); while ($ row = mysql_fetch_array ($ result) {echo $ row ['id'];} // INSERT $ SQL = "INSERT INTO 'category '('id', 'name') VALUES (NULL ,'". $ name. "')"; $ result = mysql_query ($ SQL); if (mysql_affected_rows () {echo' is inserted successfully, and the insert ID is: ', mysql_insert_id ();} else {echo 'insertion failed: ', mysql_error ();} // modify $ SQL = "UPDATE 'C Ategory 'set 'name' = '". $ name. "'where' id' = '". $ id. "'"; $ result = mysql_query ($ SQL); if (mysql_affected_rows () {echo' modified successfully! ';} // DELETE $ SQL = "DELETE FROM 'category' WHERE 'id' = '". $ id. "'"; $ result = mysql_query ($ SQL); if (mysql_affected_rows () {echo' deleted successfully! ';} // Close the connection mysql_close ($ connect );
Articles you may be interested in
  • Php mysql database operations
  • Conversion of date and unix timestamps in php and mysql
  • MySQL index Operation Command (create index, re-index, query index, delete index) Summary
  • Php extracts the birthday date from the ID card number and verifies whether it is a minor.
  • Php converts multiple consecutive spaces in a string into one.
  • How does php determine whether the current operating system is linux or windows?
  • How to query data of mysql today, yesterday, last 7 days, last 30 days, last month, and last month
  • How to change the default empty password of xampp mysql

Related Article

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.