MySQL Database connection process details

Source: Internet
Author: User

<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.