1. 连接到数据库
$con=mysql_connect("localhost","root","351117");
2. 关闭连接
mysql_close($con);
3. 选择当前要操作的数据库
mysql_select_db("my_db", $con);
4. 向表中插入数据
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...)
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Glenn', 'Quagmire', '33')");
5. 查询数据
$result = mysql_query("SELECT * FROM Persons
WHERE FirstName='Peter'
ORDER BY Age DESC");
6.遍历结果集
while($row = mysql_fetch_array($result))
{
echo $row['FirstName']." ".$row['LastName'];
echo "<br />"
}
7. 更新数据库记录
mysql_query("UPDATE Persons SET Age = '36'
WHERE FirstName='Peter' AND LastName='Griffin'")
8. 删除数库库记录
mysql_query("DELETE FROM Persons
WHERE Lastname='Griffin'")