Home > Backend Development > PHP Tutorial > php mysql database operation tutorial_PHP tutorial

php mysql database operation tutorial_PHP tutorial

WBOY
Release: 2016-07-13 17:05:06
Original
901 people have browsed it

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

"
";
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630809.htmlTechArticlephp mysql database operation tutorial This tutorial talks about three examples, all about php operating mysql database tutorials, one is Connect to the mysql database, the second is to query the database field name, the third is to query the number...
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