To connect to a database:
$con = mysql_connect (server address, user name, password);
Select database:
$select = mysql_select_db (database name);
$select = mysql_select_db (' user ');
To close the database:
mysql_close (variables connected to the database);= mysql_connect (localhost,root,root); Mysql_close ($conn) ;
Execute a MySQL query:
mysql_query (MySQL statement);
Insert new data into the database:
$insertData = "Insert [into] table name [(column name 1, column name 2, column name 3, ...)] Values (value 1, value 2, value 3, ...) ";
$sqlData = mysql_query ($insertData); Execute INSERT statement
$data = "INSERT into user (Name,age,sex) VALUES (' Chen Wen ', ' 23 ', ' Male ')";
$insertData = mysql_query ($data); Execute INSERT statement
$name = ' John doe '; $age = +; $class = ' high 31 classes '; $sql = "INSERT into user (name, age, Class) VALUES (' $name ', ' $age ', ' $class ')"; MySQL _query ($sql); Execute INSERT statement
After inserting the data, get the self-increment ID of the inserted data:
$id = mysql_insert_id ();
Echo ($id); Print the ID of the new data
In MySQL, after executing the INSERT statement, you can get the self-increment primary key ID, which can be obtained through PHP's mysql_insert_id function.
This ID is very useful, and can often be used to determine whether the insert succeeds or to perform other data operations as an association ID.
Prevent Chinese garbled:
Header ("content-type:text/html;charset=utf-8");
MySQL Execution statement