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