The code is as follows: |
Copy code |
// Link to the database $ Conn = @ mysql_connect ("localhost", "root", "88888888") or die ("link error "); /* The mysql_connect () function opens a non-persistent MySQL connection. |
Syntax
Mysql_connect (server, user, pwd, newlink, clientflag) parameter description
Optional. Specifies the server to be connected.
It can include the port number, for example, "hostname: port", or the path to the local socket, for example, ":/path/to/socket" for localhost ".
If the PHP command mysql. default_host is not defined (the default value is true), the default value is 'localhost: 3306 '.
Optional. User name. The default value is the user name of the server process owner.
Optional. Password. The default value is null.
*/
The code is as follows: |
Copy code |
// Solve Chinese garbled characters Mysql_query ("set names 'gbk '"); // Open the database Mysql_select_db ("wordpress", $ conn) or die ("Opening failed "); $ SQL = "select * from wp_posts "; |
The mysql_select_db () function sets the active MySQL database.
If yes, the function returns true. If it fails, false is returned.
Syntax
Mysql_select_db (database, connection) parameter description
Database is required. Specifies the database to be selected.
Connection is optional. MySQL connection is required. If not specified, the previous connection is used.
The code is as follows: |
Copy code |
// Execute the SQL statement $ Result = mysql_query ($ SQL, $ conn ); // Parameters required for loop printing While ($ row = mysql_fetch_array ($ result )) { Echo $ row [4]. "<br>"; // multiple quizzes. $ row [4] can only be an index but cannot be a column name. } |
The mysql_fetch_array () function retrieves a row from the result set as an associated array, or an array of numbers, or both.
Returns the array generated based on the rows obtained from the result set. If no more rows exist, false is returned.
Syntax
Mysql_fetch_array (data, array_type) parameter description
Data is optional. Specifies the data pointer to be used. This data pointer is produced by the mysql_query () function.
Array_type is optional. Specifies the result to be returned. Possible values:
MYSQL_ASSOC-associated array
MYSQL_NUM-number array
MYSQL_BOTH-default. Generate join and numeric arrays at the same time