您的位置:首页 > 编程语言 > PHP开发

自己写的一个php版的mysql工具类

2015-11-23 17:06 711 查看
<?php

class SqlHelper{
public $conn;

        public $host=SAE_MYSQL_HOST_M;

        public $port=SAE_MYSQL_PORT;

        public $user=SAE_MYSQL_USER;

        public $psw=SAE_MYSQL_PASS;

        public $db=SAE_MYSQL_DB;

        

        public function __construct(){

            $this->conn=mysql_connect($this->host.':'.$this->port,$this->user,$this->psw);
if(!$this->conn){
die('can not connect'.mysql_error());
}
mysql_select_db($this->db,$this->conn);

            mysql_query("set names utf8");

        }

        //执行查询语句

        public function execute_dql($sql){

        $res=mysql_query($sql,$this->conn) or die ('query failure111'.mysql_error());
return $res;

        }

        

        //执行插入 更新 删除 操作

      public function execute_dml($sql){
$b=mysql_query($sql,$this->conn) or die(mysql_errno());
if(!$b){
return 0;//失败
}
else{
if(mysql_affected_rows($this->conn)>0){
return 1;//成功
}
else{
return 2;//没有影响行数
}
}
}

        

        //关闭连接的方法
public function close_connect(){
if(!empty($this->conn)){
mysql_close($this->conn);
}

   }

}

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql