Add, delete, modify, and query MySQL_02, and add and delete mysql_02 in PHP Databases
1. Data Operations:
① Insert record:
INSERT a single record: INSERT tbl_name (field name ,......) VALUES (field value ,......);
INSERT multiple records: INSERT tbl_name (field name ,......) VALUES (field value ,......), (Field value ,......)......;
② Modification record:
UPDATE all records in the Table: UPDATE tbl_name SET field name = value ,......;
UPDATE records according to specified conditions: UPDATE tbl_name SET field name = value ,...... WHERE condition;
③ Delete record:
DELETE all records: delete from tbl_name;
DELETE a specified record by condition: delete from tbl_name WHERE condition;
Clear the data TABLE thoroughly: truncate table tbl_name;
④ Query records:
Query all records in the Table: SELECT * FROM tbl_name;
Specified field: SELECT field name ,...... FROM tbl_name;
Specify data by condition: SELECT field name ,...... FROM tbl_name WHERE condition;
2. database operation process:
① Connection: mysqli_connect ($ host, $ username, $ password );
② Set the character set: mysqli_set_charset ($ link, 'utf8 ');
③ Open the specified database: mysqli_select_db ($ link, $ dbName );
④ Execute the SQL statement: mysqli_query ($ link, $ SQL );
Execute INSERT, UPDATE, DELETE, and the return value is true or false;
Execute SELECT, SHOW, DESC, DESCRIBE, and Explain. The return value is the result set or record 0;
⑤ Close the connection: mysqli_close ($ link );
3. Common functions:
① Get the id generated by the last insert operation: mysqli_insert_id ($ link );
② Obtain the number of affected records generated in the previous step: mysqli_affected_rows ($ link );
③ Get all records in the result set: mysqli_fetch_all ($ result, MYSQLI_ASSOC); returns two-dimensional Index + associated array;
④ Number of records in the result set: mysqli_num_rows ($ result );