1.连接 MYSQL 服务器的函数 mysql_connect();
$con = mysql_connect("localhost","root","123456");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
2.选择数据库
mysql_select_db("david", $con);
?>
3.执行SQL语句,create,insert into,delete
//$sql = "CREATE TABLE Persons (FirstName varchar(15),LastName varchar(15),Age int)";
$sql="insert into Persons(FirstName,LastName,Age)VALUES('chen','a',33)";
mysql_query($sql,$con);
?>
4.得到记录集
mysql_query,mysql_fetch_array,
$sql="select * from Persons";
$result=mysql_query($sql,$con);
echo '共'.mysql_num_rows($result).'条记录';
while ($row = mysql_fetch_array($result))
{
//echo $row['FirstName'] . " " . $row['LastName'];
//echo "
";
printf ("ID: %s Name: %s", $row[0], $row[1]);
}
?>