1. function mysql_connect () connected to MYSQL server;
<?php
$con = mysql_connect ("localhost", "root", "123456");
if (! $con)
{
Die (' Could not connect: '. Mysql_error ());
}
?>
2. Select a database
<?php
mysql_select_db ("David", $con);
?>
3. Execute the SQL statement, Create,insert Into,delete
<?php
$sql = "CREATE TABLE Persons (FirstName varchar (), LastName varchar (), age int)";
$sql = "INSERT into Persons (firstname,lastname,age) VALUES (' Chen ', ' a ', 33)";
mysql_query ($sql, $con);
?>
4. Get a record set
Mysql_query,mysql_fetch_array,
<?php
$sql = "SELECT * from Persons";
$result =mysql_query ($sql, $con);
Echo ' Total '. mysql_num_rows ($result). ' Record ';
while ($row = Mysql_fetch_array ($result))
{
echo $row [' FirstName ']. " " . $row [' LastName '];
echo "<br/>";
printf ("ID:%s Name:%s", $row [0], $row [1]);
}
?>
"Php+mysql Learning Notes" PHP operation MySQL Database statements