PHP connection MySQL primary MySQL function summary

Source: Internet
Author: User


As a good partner in the lamp portfolio, PHP's connection to the MySQL database is an essential part of every program.
In previous versions of PHP 5.0, it was common to use the MySQL native extension function to connect, while the more powerful PDO (data abstraction layer) was recommended in later versions of 5.0.
Here's a quick summary of the common functions we typically need to interact with the database.

I. Configuring connection Database Information
1. Connect to the database
Mysql_connect ($server, $username, $password)
2. Setting the character set
Mysql_set_charset ($charset)
3. Select a database
mysql_select_db ($database _name)
Ii. Sending and executing SQL statements to the database
mysql_query ($sql);
SQL statement execution fails to return false, the execution succeeds if there are resources (such as execution of queries) to return the resource, the rest returns True.

Iii. parsing data from the returned result set
1. Returns the number of rows that affect the
Mysql_num_rows ($result) Gets the number of rows in the result set
Mysql_affected_rows () Gets the number of record rows affected by the previous operation
MYSQL_INSERT_ID (); Gets the ID that was generated by the previous step of the insert operation

2. Returns the query resource (the following is a one-row record from the result set)
Mysql_fetch_row () Digital Index
MYSQL_FETCH_ASSOC () field name index
Mysql_fetch_array () both have

3. Returns the error message
Mysql_error (); Text error message
Mysql_errno (); Numeric Encoding of error messages

Iv. Closing the database connection
Mysql_close ();

PHP connection MySQL primary MySQL function summary

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.