63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
|
|
class Dbhelper1 {
|
|
private $host = DB_HOST;
|
|
private $user = DB_USERNAME;
|
|
private $pwd = DB_PWD;
|
|
private $dbname = 'qiangwan_hwzs';
|
|
private $dblink;
|
|
public $localPath='';
|
|
private static $instance;
|
|
|
|
private function __construct() {
|
|
$obj = $this->dblink = new mysqli($this->host, $this->user, $this->pwd, $this->dbname);
|
|
if ($obj->connect_error) {
|
|
dolog($this->localPath."\n",'connect to db0 failed','sql_error');
|
|
die('connect to db failed');
|
|
}
|
|
//$this->dblink->query("set names utf8mb4");
|
|
}
|
|
|
|
public static function getinstance() {
|
|
if (!(self::$instance instanceof self)) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
public function exec_db($sql) {
|
|
// dolog($sql);
|
|
$rs = $this->dblink->query($sql) or die(dolog($this->localPath."\n".$this->dblink->error, $sql,'sql_error'));
|
|
return $rs;
|
|
}
|
|
|
|
public function exec_db_insertid($sql) {
|
|
// dolog($sql);
|
|
$rs = $this->dblink->query($sql) or die(dolog($this->localPath."\n".$this->dblink->error, $sql,'sql_error'));
|
|
return $this->dblink->insert_id;
|
|
}
|
|
|
|
public function getonerecord($sql) {
|
|
//dolog($sql);
|
|
$result = $this->dblink->query($sql) or die(dolog($this->localPath."\n".$this->dblink->error, $sql,'sql_error'));
|
|
$data = $result->fetch_all(MYSQLI_ASSOC);
|
|
mysqli_free_result($result);
|
|
return $data[0];
|
|
}
|
|
|
|
public function close() {
|
|
// dolog('close db link');
|
|
if ($this->dblink) {
|
|
mysqli_close($this->dblink);
|
|
}
|
|
}
|
|
|
|
private function __clone() {}
|
|
|
|
public function __destruct() {
|
|
$this->close();
|
|
}
|
|
}
|
|
|
|
?>
|