MYSQL entry 2 _ PHP operation MYSQL 1. Connect to MySQL locally www.2cto.com $ con = mysql_connect ("localhost", "root", "xxxxxx"); if (! $ Con) {die ('could not connect :'. mysql_error ();} else {echo "Connect success <br/> \ n";} 2. SAE connects to MySQL $ con = mysql_connect (SAE_MYSQL_HOST_M. ':'. SAE_MYSQL_PORT, SAE_MYSQL_USER, SAE_MYSQL_PASS); if (! $ Con) {die ('could not connect :'. mysql_error ();} else {echo "Connect success <br/> \ n";} mysql_select_db (SAE_MYSQL_DB, $ con); 3. disconnect MySQL mysql_close ($ con); 4. create database $ SQL = "create Database ifnot exists $ DATABASE_NAME"; if (mysql_query ($ SQL, $ con) {echo "DATABASE CREATE success <br/> \ n ";} else {echo "Error creating database :". mysql_error (). "<br/> \ n";} 5. connect to the database mysql_select_db ($ DATABASE_NAME, $ con); 6. CREATE a data TABLE $ SQL = "create table $ TABLE_NAME (namevarchar (80), ageint) ENGINE = MyISAM default charset = utf8"; if (mysql_query ($ SQL, $ con )) {echo "Table create success <br/> \ n";} else {echo "Error creating table :". mysql_error (). "<br/> \ n";} 7. query data $ SQL = "SELECT * FROM $ TABLE_NAME where name like \" % $ INPUT % \ ""; $ result = mysql_query ($ SQL, $ con ); while ($ row = mysql_fetch_array ($ result) {echo $ row ['name']. "". $ row ['age']; echo "<br/>";} 8. SET the character SET (the configured SQL operation is based on the utf8 Character SET) mysql_query ("SET NAMES 'utf8'"); mysql_query ("SET CHARACTER_SET_CLIENT = utf8 "); mysql_query ("SET CHARACTER_SET_RESULTS = utf8 ");