Home >Backend Development >PHP Tutorial >Basic class code for php to operate mysql database_PHP tutorial

Basic class code for php to operate mysql database_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:36:53933browse

Copy code The code is as follows:

$dbhost='localhost';
$dbuser=' root';
$dbpass='123456';
$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 ;
}
//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 'Delete successfully! ';
}
//Close the connection
mysql_close($connect);
?>




http://www.bkjia.com/PHPjc/736854.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/736854.htmlTechArticleCopy the code as follows: ?php $dbhost='localhost'; $dbuser='root'; $dbpass= '123456'; $dbname='products'; $connect=mysql_connect($dbhost,$dbuser,$dbpass); if(!$connect) exit('data...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn