PHP connects to MySQL database and queries all records

Source: Internet
Author: User

$host = ' localhost ';
$user _name = ' root ';
$password = ' admin ';

$conn = mysql_connect ($host, $user _name, $password);
if (! $conn)
{
Die (' Database connection failed:<br/> '. mysql_error ());
}
Echo ' Database connection successful! Continue operation ... ';

mysql_select_db (' Test ');

$sql = ' Select id,name,city from users ';
$result = mysql_query ($sql);

if ($result)
{
echo ' SQL statement: '. $sql. ' <br/> has been successfully implemented! ';
$num = mysql_num_rows ($result); Call function Mysql_num_row () to get the number of rows for a SELECT statement query result
Echo ' <br/> The SQL statement query to <b> '. $num. ' </b>www.111cn.net data ';
}

if (Mysql_close ($conn))
{
Echo ' <br/>........<br/> ';
echo ' connection to database has been successfully closed ';
}

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.