conn.php
1<?PHP2 //1, connect the database mysql_connect (' Database address ', ' username ', ' password '), as long as the connection is successful will return a resource type, connection failure, return false3 $link=mysql_connect(' localhost ', ' root ', ' 123321 ');4 if(!$link){5 //connection failure, error, interrupt program (die), die often used in production environments, usually when the program is not expected to meet the results of the use of6 die(Mysql_error());7 //Exit Quit program exit, usually for debugging8 }9 //2. Select Database mysql_select_db (' database name ')Ten if(!mysql_select_db(' Test ')){ One die(' NO FOUND DB '); A } - //3, set the transmission code for UTF8, in order to prevent garbled: 1, the database encoding must be utf8,2, database connection settings UTF8 transmission encoding, 3, the page encoding must be UTF8 - mysql_query(' Set names UTF8 '); the Mysql_close();//Close the connection, you can ignore -?>
Connection to the php-database