Occasionally to use PHP to do some MySQL database operation Test, write yourself too troublesome, the results of the search generally contains a lot of useless code, here will be PHP MySQL operation to do a summary, I hope that in the future when the use of the time no longer feel trouble.
Code as follows: <?php $dbhost = ' localhost ';//database server name $dbuser = ' root ';//connection database username $dbpass = ' 123456 ';//Connect database Password $dbname = ' Products '//database name //connection to database $connect =mysql_connect ($dbhost, $dbuser, $dbpass); if (! $connect) exit (' Database connection failed! '); mysql_select_db ($dbname, $connect); mysql_query (' Set names UTF8 ')//Set encoding //query Operation $sql = "SELECT * from ' Category '"; $result =mysql_query ($sql); while ($row =mysql_fetch_array ($result)) { echo $row [' id '];}//Insert action $sql = INSERT INTO ' category ' (' id ', ' name ') VALUES (NULL, ' ". $name.") "; $result =mysql_query ($sql); if (Mysql_affected_rows ()) { echo ' Insert succeeded, insert ID: ', mysql_insert_id ();} else{ echo ' Insert failed: ', mysql_error ();}//Modify Operation $sql = "UPDATE ' category ' SET ' name ' = '". $name. "' WHERE ' id ' = '. $id. "'"; $result =mysql_query ($sql); if (Mysql_affected_rows ()) { echo ' modified successfully! '; }//delete operation $sql = "Delete from ' category ' WHERE ' id ' = '". $id. "'"; $result =mysql_query ($sql); if (Mysql_affected_rows ()) { echo ' delete succeeded! '; }//Close connection mysql_close ($connect);?> &NBSp