Home > Article > Backend Development > php mysql database operation tutorial_PHP tutorial
php mysql database operation tutorial This tutorial talks about three examples, all about PHP operating mysql database. The first is to connect to the mysql database, the second is to query the database field name, and the third is to query the database records.
php tutorial mysql tutorial database tutorial operation tutorial
This tutorial talks about three examples, all about PHP operating mysql database. The first is to connect to the mysql database, the second is to query the database field name, and the third is to query the database records.
*/
//Connect to mysql database
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
or die("could not connect: " . mysql_error());
Print ("connected successfully");
Mysql_close($link);
//Query mysql field name
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$fields = mysql_list_fields("database1", "table1", $link);
$columns = mysql_num_fields($fields);for ($i = 0; $i < $columns; $i++) {
echo mysql_field_name($fields, $i) . "n";
}
//Query data
$conn=mysql_connect("localhost","phpdb","phpdb")
or die("Unable to connect to database server: ".mysql_error());
mysql_select_db("test",$conn) or die ("Cannot select database: ".mysql_error());
$result = mysql_query("select * from user",$conn);
while($row=mysql_fetch_array($result)){
print "name:".$row[1];
print "address:".$row[3];
print " tel:".$row[4];
print "email:".$row[5];
echo
"
";
}