Here is the process-oriented MySQL link, two files, config.php and conn.php, just record, do not like to spray, but also want to have good suggestions, the code is as follows:
config.php
<?php
/*
* The configuration variables related to database links are stored in this file, which facilitates later development of the changes
* This is only part of the configuration
* **/
$hostname = ' localhost ';
$username = ' root ';
$password = ";
$database = ' AA ';
?>
conn.php
<?php
/* This is mysql_connect process-oriented link, just write a box, the details will be added later **/
Require ("config.php");//path to correct
[Email Protected]_connect ($hostname, $username, $password) or Die ("link error");
mysql_query ("Set names ' UTF8 '"); Set encoding
mysql_select_db ($database); Select Database
$sql = "SELECT * from user";
$res = mysql_query ($sql, $conn); Execute SQL statement
/* Loop through the data **/
while ($row = Mysql_fetch_array ($res)) {
echo $row [' name '];
}
/* Write Data **/
$sql 1 = "INSERT into user (name) values (' Longo ')";
mysql_query ($sql 1);
/* Update data name and age**/
$sql 2= "Update user set Name= ' Longo ', age= ' 100 '";
$result =mysql_query ($sql 2);
if ($result) {echo "succeeded";} else {echo "failed";}
Mysql_freeresult ($res);
Mysql_close ();
?>
PHP MySQL Database link Simple example