mysqlTool.php 工具类类页面
<?php
class SqlTool{
private $conn;
private $host="localhost";
private $user="root";
private $password="root";
private $db="test";
function SqlTool(){
$this->conn=mysql_connect($this->host,$this->user,$this->password);
if(!$this->conn){
die("连接数据库".mysql_eror());
}
mysql_select_db($this->db,$this->conn);
mysql_query("set names utf8");
}
//select dql
pubulic function execute_dql($sql){
$res=mysql_query($sql,$this->conn) or die(mysql_error());
return $res;
}
//完成对dml的操作 insert delete update
public funciton execute_dml($sql){
$b=mysql_query($sql,$this->conn);
if(!$b){
return 0;
}else{
if(mysql_affacted_row($this->conn)){
return 1;//表示成功
}
}else{
return 2;//没有影响到行数
}
}
}
?>
引入操作页面 mysqlDomo2.php
<?php
class SqlTool{
private $conn;
private $host="localhost";
private $user="root";
private $password="root";
private $db="test";
function SqlTool(){
$this->conn=mysql_connect($this->host,$this->user,$this->password);
if(!$this->conn){
die("连接数据库".mysql_eror());
}
mysql_select_db($this->db,$this->conn);
mysql_query("set names utf8");
}
//select dql
pubulic function execute_dql($sql){
$res=mysql_query($sql,$this->conn) or die(mysql_error());
return $res;
}
//完成对dml的操作 insert delete update
public funciton execute_dml($sql){
$b=mysql_query($sql,$this->conn);
if(!$b){
return 0;
}else{
if(mysql_affacted_row($this->conn)){
return 1;//表示成功
}
}else{
return 2;//没有影响到行数
}
}
}
?>