This is a simple PHP and MySQL data query data Simple introductory article, we talked about the most important functions of the detailed introduction, the need for students to see.
| The code is as follows |
Copy Code |
|
Link Database
$conn = @mysql_connect ("localhost", "root", "88888888") or Die ("link error");
/*
The mysql_connect () function opens a non-persistent MySQL connection. |
Grammar
mysql_connect (server,user,pwd,newlink,clientflag) parameter description
Server is optional. Specifies the server to connect to.
You can include a port number, such as "Hostname:port", or a path to a local socket, such as ":/path/to/socket" for localhost.
If PHP directive mysql.default_host is undefined (by default), the default value is ' localhost:3306 '.
User is optional. User name. The default value is the user name of the server process owner.
PWD is optional. Password. The default value is a blank password.
*/
| The code is as follows |
Copy Code |
|
Solve Chinese garbled characters
mysql_query ("Set names ' GBK '");
Open Database
mysql_select_db ("WordPress", $conn) or Die ("Open failed");
$sql = "SELECT * from Wp_posts"; |
The mysql_select_db () function sets the active MySQL database.
If successful, the function returns True. If it fails, it returns false.
Grammar
mysql_select_db (database,connection) parameter description
Database Required. Specifies the database to select.
Connection is optional. Specify MySQL connection. If not specified, the previous connection is used.
| The code is as follows |
Copy Code |
|
Execute SQL statement
$result = mysql_query ($sql, $conn);
Required parameters for loop printing
while ($row = Mysql_fetch_array ($result))
{
Echo $row [4]. "
";//test multiple times, $row [4] can only be indexed, cannot be a column name, depressed in ing
} |
The Mysql_fetch_array () function takes a row from the result set as an associative array, or as a numeric array, or both
Returns an array based on the rows obtained from the result set, or False if there are no more rows.
Grammar
Mysql_fetch_array (data,array_type) parameter description
Data is optional. Specifies the data pointers to be used. The data pointer is the result of the mysql_query () function.
Array_type is optional. Specifies what kind of results to return. Possible values:
MYSQL_ASSOC-Associative arrays
Mysql_num-numeric array
Mysql_both-Default. Simultaneous generation of associative and numeric arrays
http://www.bkjia.com/PHPjc/629152.html www.bkjia.com true http://www.bkjia.com/PHPjc/629152.html techarticle This is a simple PHP and MySQL data query data Simple introductory article, we talked about the most important functions of the detailed introduction, the need for students to see. The code is as follows ...