<?php
1. Link MySQL server
$conn = mysql_connect ("localhost", "root", 199452);
2. Select a database
$db = mysql_select_db ("Xinlangweibo");
3. Setting the Encoding
mysql_query ("Set names UTF8");
?
4. Working with the database
Increase
$sql = "INSERT into User2 (name,age) VALUES (' Xiao Ming ', 20)";
Delete
$sql = "Delete from user2 where id=4";
Modify
$sql = "Update user2 set age=30 where id=3";
$res =mysql_query ($sql, $conn);
if (! $res) {
Die ("Operation failed! ". Mysql_error ());
}
if (Mysql_affected_rows ($conn) >0) {
echo "Operation succeeded! ";
}else{
echo "Number of rows not affected";
}
5. Accept the results of the return and deal with them
The return value is bool and does not require processing
6. Close the connection and release the resource
Because $res is a Boolean value, there is no need to release resources.
Mysql_free_result ($res);
The following sentence can be written or not written
Mysql_close ($conn);
?>