Detailed steps for accessing a database using php mysql: accessing data using mysql
Steps for accessing the mysql database using php
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 () also applies}
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;
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!