Add, delete, modify, and query MySQL_02, and add and delete mysql_02 in PHP Databases

Source: Internet
Author: User

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 );

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.