How to use PHP to connect to MySQL instance
A simple address book, the database name is TXL, the database has only one table called Personal_info, the table has 5 fields
Pi_idpi_namepi_telpi_qqpi_email
First we want to create a database:
Create databases TXL;
then we set up table
CREATE table ' Personal_ Info ' (
' pi_id ' bigint () not NULL auto_increment,
' pi_name ' varchar () is not null,
' pi_tel ' varchar (15) Default NULL,
' pi_qq ' varchar (all) default null,
' pi_email ' varchar () default NULL,
PRIMARY KEY (' pi_id ')
) Engine=myisam DEFAULT Charset=utf8 auto_increment=4; The SQL statement on the
is simple enough to literally guess what it means.
The following is a list of all field information connected to the database and showing the table Personal_info:
//connsql.php
!--? php
$mysql _server_name= "localhost"; Database server name
$mysql _username= "root";//Connect database user name
$mysql _password= "root";//Connect database password
$mysql _database= "LXR";// Database name
//Connect to Database
$conn =mysql_connect ($mysql _server_name, $mysql _username,
$mysql _password);
//SQL statement to extract information from table
$strsql = "SELECT * from Personal_info";
//Execute SQL query
$result =mysql_db_query ($mysql _ Database, $strsql, $conn);
//Get query Results
$row =mysql_fetch_row ($result);
Echo ';
Echo '
Show Field names
echo "\ n
';
\ n "; for ($i =0; $i {echo '
'. Mysql_field_name ($result, $i); echo " | \ n "; } echo "
\ n "; Locate the first record Mysql_data_seek ($result, 0); Loop out record while ($row =mysql_fetch_row ($result)) {echo "
\ n "; for ($i =0; $i {echo '
'; echo "$row [$i]"; Echo ' | '; } echo "
\ n "; } echo "
\ n ";
echo "";
Freeing resources
Mysql_free_result ($result);
Close connection
Mysql_close ();
?>
Here is the result of the operation:
Pi_idpi_namepi_telpi_qqpi_email1zhangsan13911111111642864125zhangsan@126.com2lisi1312222222263958741lisi
@163.com3wangwu13833333333912345678wangwu@sohu.com
The so-called "original Aim", the complex operation is also based on the above, all without the above basic steps, when necessary to check the relevant manual can be resolved.
http://www.bkjia.com/PHPjc/950330.html www.bkjia.com true http://www.bkjia.com/PHPjc/950330.html techarticle How to use PHP to connect to the MySQL instance of a simple address book, the database name is TXL, the database only a table called Personal_info, the table has 5 fields pi_idpi_namepi_telpi_qqpi_e ...