<?php
$id = $_post[' id ']; Receive parameter ID
$name = $_post[' name ']; Receive parameter user name
$PWD = MD5 ($_post[' pwd "); Receive parameter password, MD5 encryption
Database configuration Parameters
$db _host = ' db_host '; Database host address, such as localhost
$db _user = ' db_user '; Database user name
$db _pwd = ' db_pwd '; Database Password
$db _database = ' db_database '; Selected Database library name
$connection = mysql_connect ($db _host, $db _user, $db _pwd);//Database connection Resources
mysql_query ("Set names ' UTF8 '"); Setting the database character set
if (! $connection) {
Die ("could does connect to the database.\n". Mysql_error ());
}
$selectedDb = mysql_select_db ($db _database);//Select Database
if (! $selectedDb) {
Die ("could not to the database\n". Mysql_error ());
}
$id = intval ($id);
$name = mysql_real_escape_string ($name); parameter handling prevents SQL injection
$pwd = mysql_real_escape_string ($PWD); parameter handling prevents SQL injection
$insertSql = "INSERT into Hsh_user (ID, name, pwd) VALUES ($id, ' $name ', ' $pwd ')";//Prepare SQL statements
$flag = mysql_query ($INSERTSQL); Execute SQL statement
if (! $flag) {
Die ("Query error\n". Mysql_error ());
}
mysql_close ($connection); To close a database connection
?>
MySQL Database connection process details