PHP and MySQL is a gold combination, now let's talk about PHP query MySQL database record implementation, mainly use the function mysql_connect mysql_query mysql_select_db Mysql_fetch_ Array of four PHP functions, see below for implementation.
PHP tutorial and MySQL tutorial is a gold combination, now let's talk about PHP query MySQL database tutorial record implementation, mainly use the function mysql_connect mysql_query mysql_select_db Mysql_fetch_ Array of four PHP functions, see below for implementation.
*/
$hostname = "localhost"; Define the name of the MySQL server to which you are connected
$username = "root"; Define the user name to use for the connection
$password = ""; Define the password to use for the connection
$link =mysql_connect ($hostname, $username, $password); Open mSQL Connection
mysql_query (' Set names gb2312; '); Convert encoding to support Chinese
mysql_select_db ("test"); Select the Operation Library as test
$query = "SELECT * from Friends"; Define SQL
$result =mysql_query ($query); Send SQL query
while ($rows =mysql_fetch_array ($result))
{
echo "ID:". $rows [id];
echo "
Www.bKjia.c0mn ";
echo "Name:". $rows [name];
echo "
n ";
echo "Sex for:". $rows [Sex];
echo "
n ";
echo "Birthday for:". $rows [Birthday];
echo "
n ";
echo "Address:". $rows [Address];
echo "
n ";
}
Releasing the result set
Mysql_free_result ($result);
Conditional query
$query = "SELECT * from friends where id=1"; Define SQL
$result = mysql_query ($query); Send SQL query
Echo mysql_result ($result, 0, "name"); Output name Result
echo "
";
Echo mysql_result ($result, 0, "birthday"); Output Birthday Results
echo "
";
Echo mysql_result ($result, 0, "sex"); Output sex Results
echo "
";
Echo mysql_result ($result, 0, "address"); Output address Results
Related actions
$conn =mysql_connect (' localhost ', ' root ', ');//Open connection
$fields =mysql_list_fields ("Test", "Friends", $conn); List information for the Test Library friends table
$cols =mysql_num_fields ($fields); Get the number of results
for ($i =0; $i < $cols; $i + +)//Cycle
{
Echo Mysql_field_name ($fields, $i). " n "; Output Field Name
echo "
";
}
/*
Summarize
Querying database records in PHP is fairly simple and common, as long as you record the above functions to achieve data query.
*/
http://www.bkjia.com/PHPjc/630777.html www.bkjia.com true http://www.bkjia.com/PHPjc/630777.html techarticle PHP and MySQL is a gold combination, now let's talk about PHP query MySQL database record implementation, mainly use the function mysql_connect mysql_query mysql_select_db Mysql_fetch_ Array of four ...