Php steps to access the mysql database, phpmysql Database

Source: Internet
Author: User

Php steps to access the mysql database, phpmysql Database

The official saying is that mysql_query () has been discarded since 5.5. Of course, you can read the manual for a few frequently used items. Here is a simple record. A little memory can be recovered after my amnesia. I have been forgetting to use the framework native recently.

1. Open mysql connection

$ Resource1 = mysql_connect ('localhost', 'root', 'root123'); // parameter 1 Host Name or Host ip address, parameter 2 database user name, parameter 3 Database User Password

If (! $ Resource1 ){

Die ('could not connect: Error code: '. mysql_errno ().' error message: '. mysql_error); // mysql_query () is also applicable

}

 

2. Select a database

Mysql_select_db ('db1', $ resource1); // parameter 1 Database Name, mysql connection in step 2 of parameter 2

 

3. Now you can execute SQL statement operations.

$ Result = mysql_query ("select * from users", $ resource1); // parameter 1 SQL statement, mysql connection in step 2 of parameter 2

When an SQL statement is a query statement, you can use mysql_fetch_array ($ result, MYSQL_ASSOC) to return data of the resource type );

The associated array obtained by MYSQL_ASSOC is equivalent to the mysql_fetch_assoc () function.

The numeric index array obtained by MYSQL_NUM is equivalent to the mysql_fetch_row () function.

If the SQL statement is another statement that is modified, true is returned if the statement is successfully modified. Otherwise, false is returned. There are many possibilities of false, statement errors, and insufficient permissions;

 

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.