代码 复制 - 运行
class SqlHelper {
private $mysqli;
private static $host = "localhost";
private static $user = "dbuser";
private static $pwd = "dbpwd";
private static $db = "dbname";
public function __construct() {
$this->mysqli = new mysqli ( self::$host, self::$user, self::$pwd, self::$db );
if ($this->mysqli->connect_error) {
die ( "连接失败" . $this->mysqli->connect_error );
}
$this->mysqli->query ( "SET NAMES gbk;" );
}
public function exec_dql($sql) {
$res = $this->mysqli->query ( $sql ) or die ( "操作失败dql" . $this->mysqli->error );
return $res;
}
public function exec_dml($sql) {
$res = $this->mysqli->query ( $sql ) or die ( "操作失败dml" . $this->mysqli->error );
if (! $res) {
return 0; //表示失败
} else {
if ($this->mysqli->affected_rows > 0) {
return 1; //成功
} else {
return 2; //无影响
}
}
}
}
本帖最后由 肖阳_洛阳 于 2013-02-27 21:25 编辑