Here is a PHP link to the MySQL database
PHP and MySQL link and query the whole process
1. Compounding:
php.ini load MySQL component:
Before the Extension=php_mysql.dll; Remove
Extension_dir = "" Path is correct
2. PHP syntax
PHP link MySQL function
Mysql_connect: Open MySQL Link
mysql_select_db: Open a Database
@ and Or die hide errors and condition display
Usage: mysql_connect ("host", "username", "password")
mysql_select_db ("Open database", connection identifier);
(If the connection identifier is not specifically declared, it is assumed to be the last open connection.) )
3. How to execute an SQL statement
mysql_query (SQL statement, connection identifier);
Description: mysql_query is used to send a query to the database server's current database based on the connection identifier, which is tacitly considered to be the last open connection if the connection identifier defaults.
Return value: Returns a result identifier after success, false when failed.
4, two kinds of query function Array/row difference
Format: mysql_fetch_row (Result);
Description: Mysql_fetch_row to query the results of the row to save to the array, the array subscript starting from 0, each array element corresponds to a field. By looping, you can get all the results of the query.
Format: mysql_fetch_array (Result);
Description: Mysql_fetch_array and Mysql_fetch_row functions are basically the same, except that it can be indexed by the offset from 0, but also by domain name. Value returns all the field values for the next row and saves them to an array, with no rows returning false.
5, garbled problem
The code is as follows |
Copy Code |
mysql_query ("Set names ' GBK '"); Solve Chinese garbled |
6. Example:
The code is as follows |
Copy Code |
A, linked databases $conn = @ mysql_connect ("localhost", "Database user name", "Database Password") or Die ("Database link error"); mysql_select_db ("Database name", $conn); mysql_query ("Set names ' utf-8′"); Use utf-8 Chinese code; B, query the database test $SQL = "SELECT * from" table name ' ORDER by Desc ' in a field; $query =mysql_query ($SQL); while ($row =mysql_fetch_array ($query)) { Print_r ($row); } |
Source code into the tutorial for my original, only for learning, such as the use of illegal use and the author has nothing to do.