<?php
/** 
 * UQ云商：	www.uqcms.com  
 * 联系QQ：	2200631718 
 * 可免费商用，需要留UQ云商链接作为交换，只首页底部留取即可，不影响使用。
 */

 class dbi { function conn($uq0, $uq1, $uq2, $uq3) { $this->conn = new mysqli($uq0, $uq1, $uq2, $uq3); if(!$this->conn){ error_404('数据库没有连接上'); } $this->conn->query("SET names UTF8"); } function query($uq4) { if(empty($uq4)){ return false; } $t1 = microtime(true); $uq6 = $this->conn->query($uq4); $uq7 = microtime(true) - $t1; if($uq7 >= '0.1'){ db_log(date('Y-m-d H:i:s').' SLOW: '.$uq4); } if($this->conn->error){ echo $this->conn->error; echo '<br>'; echo $uq4.'<br>'; db_log(date('Y-m-d H:i:s').' ERROR: '.$uq4); return false; } if($uq6){ return $uq6; }else{ return false; } } function fetch_array($uq8) { return $uq8->fetch_array(MYSQLI_ASSOC); } function add($uq9, $uq10, $uq11 = 0) { $uq12 = ""; $uq13 = ""; foreach($uq10 as $uq14 =>$uq15){ if(@trim($uq15) !== ''){ $uq12 .= "`".$uq14."`,"; if (!get_magic_quotes_gpc()){ $uq13 .= " '".@addslashes($uq15)."',"; }else{ $uq13 .= " '".$uq15."',"; } } } $uq12=rtrim($uq12,","); $uq13=rtrim($uq13,","); $uq4 = "INSERT INTO `{$uq9}` (".$uq12.") VALUES  (".$uq13.");"; if($uq11 == 1){ echo $uq4; } return $this->query($uq4); } function update($uq9, $uq10, $uq16, $uq17 = '0') { $uq13=""; foreach($uq10 as $uq14=>$uq15){ if(trim($uq15) !== ''){ if (!get_magic_quotes_gpc()){ $uq13 .= "`".$uq14."` = '".addslashes($uq15)."',"; }else{ $uq13 .= "`".$uq14."` = '".$uq15."',"; } }else{ $uq13 .= "`".$uq14."` = NULL,"; } } $uq13=rtrim($uq13,","); if($uq17 == '1'){ echo "UPDATE `{$uq9}` SET ".$uq13." where {$uq16} "; }else{ $uq4 = "UPDATE `{$uq9}` SET ".$uq13." where {$uq16} "; } return $this->query($uq4); } public function insert_id() { return $this->conn->insert_id; } function get_one($uq4) { $uq6 = $this->query($uq4); if($uq6){ $uq10 = $uq6->fetch_array(MYSQLI_ASSOC); if($uq10){ return $uq10; }else{ return true; } }else{ return false; } } function get_all($uq4) { $uq6 = $this->query($uq4); if($uq6){ while($uq18 = $uq6->fetch_array(MYSQLI_ASSOC)){ $uq10[] = $uq18; } if(isset($uq10)){ return $uq10; }else{ return false; } } } public function delete($uq9, $uq19 = "", $uq17 = '0') { if(empty($uq19)) { return false; } $uq4 = "delete from $uq9 where 1=1 and $uq19"; if($uq17){ echo $uq4; } if(!$this->query($uq4)) return false; return true; } public function autocommit() { $this->conn->autocommit(false); } public function commit() { $this->conn->commit(); } public function rollback() { $this->conn->rollback(); } public function autocommit_free_result() { $this->conn->autocommit(); } public function free_result() { $uq20 = func_get_args(); foreach($uq20 as $uq6) { if(is_resource($uq6) && get_resource_type($uq6) === 'mysql result') { return $this->conn->free_result($uq6); } } } public function close() { $this->conn->close; } } 