First, connect the database
1. Mysql_connect: Open MySQL Link
Mysql_connect (' host ', ' username ', ' password ')
2. mysql_select_db: Open a Database
mysql_select_db (' database name ', $ link identifier)//link identifier not filled by default is the last open connection
3, mysql_query ("Set names ' GBK '") to solve the problem of Chinese garbled;
mysql_query ("Set Names ' code (UTF8 or GBK) '")//utf8 cannot have "-"
second, query data
1, mysql_query (SQL statement, connection identifier);
$sql = "SELECT * FROM Test"
$result =mysql_query ($sql)//Connection identification defaults think last opened link
Get error message
$result = @mysql_query ($sql) or Die (Mysql_error ())
2, get the results of the query
A, mysql_fetch_row ($result);
$row =mysql_fetch_row ($result);
echo $row [0];
B, Mysql_fetch_array ($result);
$row =mysql_fetch_array ($result);
echo $row [0];
echo $row [' key '];
Description: The Mysql_fetch_array and mysql_fetch_row functions are basically the same, except that it can be indexed with a domain name in addition to the 0-based offset.
The value returns all the field values for the next row, saves them in an array, and returns False when there are no rows.
http://www.bkjia.com/PHPjc/323835.html www.bkjia.com true http://www.bkjia.com/PHPjc/323835.html techarticle I. Connect database 1, mysql_connect: Open MySQL link mysql_connect (' Host ', ' username ', ' password ') 2, mysql_select_db: Opens a database mysql_select_db (' Database name ...