PHP query MySQL data sheet record implementation Code _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.