The basic class code for php operations on the mysql database. Copy the code as follows :? Php $ dbhostlocalhost; $ dbuserroot; $ dbpass123456; $ dbnameproducts; $ connectmysql_connect ($ dbhost, $ dbuser, $ dbpass); if (! $ Connect) exit (data
The code is as follows:
$ Dbhost = 'localhost ';
$ Dbuser = 'root ';
$ Dbpass = '20140901 ';
$ Dbname = 'products ';
$ Connect = mysql_connect ($ dbhost, $ dbuser, $ dbpass );
If (! $ Connect) exit ('database connection failed! ');
Mysql_select_db ($ dbname, $ connect );
Mysql_query ('set names utf8 ');
// Query
$ SQL = "SELECT * FROM 'Category '";
$ Result = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ result )){
Echo $ row ['id'];
}
// Insert
$ SQL = "INSERT INTO 'category '('id', 'name') VALUES (NULL,'". $ name ."')";
$ Result = mysql_query ($ SQL );
If (mysql_affected_rows ()){
Echo 'Insert successful, insert ID: ', mysql_insert_id ();
} Else {
Echo 'insertion failed: ', mysql_error ();
}
// Modify
$ SQL = "UPDATE 'category' SET 'name' = '". $ name. "'where' ID' ='". $ id ."'";
$ Result = mysql_query ($ SQL );
If (mysql_affected_rows ()){
Echo 'modification successful! ';
}
// Delete
$ SQL = "DELETE FROM 'category' WHERE 'id' = '". $ id ."'";
$ Result = mysql_query ($ SQL );
If (mysql_affected_rows ()){
Echo 'deleted! ';
}
// Close the connection
Mysql_close ($ connect );
?>
The http://www.bkjia.com/PHPjc/736854.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/736854.htmlTechArticle code is as follows :? Php $ dbhost = 'localhost'; $ dbuser = 'root'; $ dbpass = '000000'; $ dbname = 'products'; $ connect = mysql_connect ($ dbhost, $ dbuser, $ dbpass); if (! $ Connect) exit ('data...