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';
}