1 <?php
2
3 /**
4 * 函数名称:sqlHelper.class.php
5 * 函数功能:mysqli面向对象进行dql dml 查询
6 * 函数作者:张真贵
7 * 创建时间:2015-01-05
8 * 修改时间:
9 */
10 class SqlHelper
11 {
12 private $mysqli;
13 private static $host = 'localhost';
14 private static $root = "root";
15 private static $password = "";
16 private static $dbname = "test";
17 public function __construct()
18 {
19 # code...
20 $this->mysqli = new mysqli(self::$host,self::$root,self::$password,self::$dbname);
21 if ($this->mysqli->connect_error) {
22 # code...
23 die("连接失败".$this->mysqli->connect_error);
24 }
25 $this->mysqli->query("set names utf8");
26 }
27 public function execute_dql($sql){
28 $res = $this->mysqli->query($sql) or die("dql失败".$this->mysqli->error);
29 return $res;
30 }
31 public function execute_dml($sql){
32 $res = $this->mysqli->query($sql) or die("dml失败".$this->mysqli->error);
33 if (!$res) {
34 # code...失败
35 return 0;
36 }elseif ($this->mysqli->fetch_rows > 0) {
37 # code...成功
38 return 1;
39 }else{
40 # code...没有影响行数
41 return 2;
42 }
43 }
44 }
45 ?>