Php and Mysql 1. open phpMyAdmin
Http: // localhost/phpmyadmin
2. establish a connection
$ Con = mysql_connect ($ db_host, $ db_user, $ db_pass)
3. close the connection
Mysql_close ($ con );
4. open the database (this database should be created in phpmyadmin)
If (mysql_select_db (web_01) {echo "selected database succeeded";} else {echo "failed to select database ";}5. execute SQL statements
After the database is connected, the query command can be sent to the database in the form of mysql_query and SQL statements.
If (mysql_query ('Insert into my_table (name) values ("taylor") ') {echo"
"." Inserted successfully ";} else {echo"
"." Insertion failed ";}
Insert a "taylor" field to the name attribute in the my_table table.
6. SQL statement error message printing
Echo mysql_error ();
7. prevent Chinese garbled characters
Mysql_query ('set names utf8 ');