Home > Backend Development > PHP Tutorial > PHP connects to mysql database and queries and records all records_PHP tutorial

PHP connects to mysql database and queries and records all records_PHP tutorial

WBOY
Release: 2016-07-13 17:05:02
Original
1207 people have browsed it

php connects to mysql database and queries and records all records The following is a simple PHP database operation program. We first talk about PHP connecting to the MySQL database, then execute the SQL query statement to display the records we want, and finally close the connection with the MySQL database.

php tutorial to connect mysql tutorial database tutorial and query and record all records
The following is a simple PHP database operation program. We first talk about PHP connecting to the MySQL database, then execute the SQL query statement to display the records we want, and finally close the connection with the MySQL database.
*/
$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
Die('Database connection failed:
'.mysql_error());
}
echo 'Database connection successful! Continue...';

mysql_select_db('test');

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

if($result)
{
Echo 'sql statement:' . $sql . '
has been successfully executed! ';
$num = mysql_num_rows($result); //Call the function mysql_num_row() to obtain the number of rows in the select statement query result
echo '
This sql statement queries '.$num.'www.bKjia.c0m row data';
}

if(mysql_close($conn))
{
echo '
.....
';
echo 'The connection to the database has been closed successfully';
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630822.htmlTechArticlephp connects the mysql database and queries and records all records. The following is a simple php program to operate the database. We first Talk about php connecting to the mysql database, and then execute the sql query statement and then put us...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template