您的位置:首页 > 数据库 > MySQL

mysqli面向对象进行dql dml 查询

2015-01-05 23:12 204 查看
<?php

/**
* 函数名称:sqlHelper.class.php
* 函数功能:mysqli面向对象进行dql dml 查询
* 函数作者:张真贵
* 创建时间:2015-01-05
* 修改时间:
*/
class SqlHelper
{
private $mysqli;
private static $host = 'localhost';
private static $root = "root";
private static $password = "";
private static $dbname = "test";
public function __construct()
{
# code...
$this->mysqli = new mysqli(self::$host,self::$root,self::$password,self::$dbname);
if ($this->mysqli->connect_error) {
# code...
die("连接失败".$this->mysqli->connect_error);
}
$this->mysqli->query("set names utf8");
}
public function execute_dql($sql){
$res = $this->mysqli->query($sql) or die("dql失败".$this->mysqli->error);
return $res;
}
public function execute_dml($sql){
$res = $this->mysqli->query($sql) or die("dml失败".$this->mysqli->error);
if (!$res) {
# code...失败
return 0;
}elseif ($this->mysqli->fetch_rows > 0) {
# code...成功
return 1;
}else{
# code...没有影响行数
return 2;
}
}
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: