class AppMysqli
{
var $sql_id;
var $sql_qc=0;
function __construct($dbhost, $dbuser, $dbpw, $dbname = '', $charset = 'utf8',$newlink=false)
{
$this->sql_id = new mysqli($dbhost, $dbuser, $dbpw, $dbname, 3306);
if(mysqli_connect_errno()) {
$this->sql_id = false;
showErr("DataBase","MYSQL 连接数据库失败,请确定数据库用户名,密码设置正确
");
}
else{
$this->sql_id->set_charset($charset);
}
}
function close() {
$this->sql_qc=0;
return mysqli_close($this->sql_id);
}
function select_database($dbName)
{
return mysqli_select_db($dbName, $this->sql_id);
}
function fetch_array($query, $result_type = MYSQLI_ASSOC)
{
return mysqli_fetch_array($query, $result_type);
}
function real_escape_string($s){
return mysqli_real_escape_string($this->sql_id,$s);
}
function query($sql)
{
$this->sql_qc++;
$sql = str_replace("{pre}",$GLOBALS['MAC']['db']['tablepre'],$sql);
// 检查最终SQL是否为空
if (empty($sql) || !is_string($sql) || trim($sql) === '') {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
$caller = isset($backtrace[1]) ? $backtrace[1]['function'] : 'unknown';
error_log("AppMysqli::query - 执行空SQL,调用者:{$caller},处理后的SQL:" . var_export($sql, true));
return false;
}
return mysqli_query($this->sql_id,$sql);
}
function queryArray($sql,$keyf='')
{
$array = array();
$result = $this->query($sql);
while($r = $this->fetch_array($result))
{
if($keyf){
$key = $r[$keyf];
$array[$key] = $r;
}
else{
$array[] = $r;
}
}
return $array;
}
function affected_rows()
{
return mysqli_affected_rows($this->sql_id);
}
function num_rows($query)
{
return mysqli_num_rows($query);
}
function insert_id()
{
return mysqli_insert_id($this->sql_id);
}
function selectLimit($sql, $num, $start = 0)
{
if ($start == 0){
$sql .= ' LIMIT ' . $num;
}
else{
$sql .= ' LIMIT ' . $start . ', ' . $num;
}
return $this->query($sql);
}
function getOne($sql, $limited = false)
{
// 原始SQL参数非空检查
if (empty($sql) || !is_string($sql)) {
error_log("AppMysqli::getOne - 传入的SQL参数为空,调用栈: " . json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5)));
return false;
}
if ($limited == true){
$sql = trim($sql . ' LIMIT 1');
}
// 添加LIMIT后再次检查
if (empty($sql) || trim($sql) === '') {
error_log("AppMysqli::getOne - 添加LIMIT后SQL为空,原始SQL参数:" . var_export($sql, true));
return false;
}
$res = $this->query($sql);
if ($res !== false){
$row = mysqli_fetch_row($res);
return $row[0];
}
else{
return false;
}
}
function getRow($sql)
{
$res = $this->query($sql);
if ($res !== false){
return mysqli_fetch_assoc($res);
}
else{
return false;
}
}
function getAll($sql)
{
$res = $this->query($sql);
if ($res !== false){
$arr = array();
while ($row = mysqli_fetch_assoc($res)){
$arr[] = $row;
}
return $arr;
}
else{
return false;
}
}
function getTableFields($dbName,$tabName)
{
$sql = "SELECT * FROM " . $tabName .' limit 1';
$row = $this->query($sql);
$res = mysqli_fetch_fields($row);
$fields = array();
foreach($res as $v)
{
$fields[] = $v->name;
}
return $fields;
}
function Exist($tabName,$fieldName ,$ID)
{
$SqlStr="SELECT * FROM ".$tabName." WHERE ".$fieldName."=".$ID;
$res=false;
try{
$row = $this->getRow($SqlStr);
if($row){ $res=true; }
unset($row);
}
catch(Exception $e){
}
return $res;
}
function AutoID($tabName,$colname)
{
$n = $this->getOne("SELECT Max(".$colname.") FROM [".$tabName."]");
if (!is_numeric(n)){ $n=0; }
return $n;
}
function Add($tabName,$arrFieldName ,$arrValue)
{
$res=false;
if (chkArray($arrFieldName,$arrValue)){
$sqlcol = "";
$sqlval = "";
$rc=false;
foreach($arrFieldName as $a){
if($rc){ $sqlcol.=",";}
$sqlcol .= $a;
$rc=true;
}
$rc=false;
foreach($arrValue as $b){
if($rc){ $sqlval.=",";}
$sqlval .= "'". $b."'";
$rc=true;
}
$sql = " INSERT INTO " . $tabName." (".$sqlcol.") VALUES(".$sqlval.")" ;
$res = $this->query($sql);
}
return $res;
}
function Update($tabName,$arrFieldName , $arrValue ,$KeyStr,$f=0)
{
$res=false;
if (chkArray($arrFieldName,$arrValue)){
$sqlval = "";
$rc=false;
for($i=0;$iquery($sql);
}
return $res;
}
function Delete($tabName,$KeyStr)
{
$res=false;
$sql = "DELETE FROM ".$tabName." WHERE ".$KeyStr;
$res = $this->query($sql);
return $res;
}
}
Fatal error: Uncaught Error: Class "AppMysqli" not found in /www/wwwroot/v.cechi360.com/inc/common/function.php:80
Stack trace:
#0 /www/wwwroot/v.cechi360.com/inc/module/vod.php(282): getDbConnect()
#1 /www/wwwroot/v.cechi360.com/index.php(42): include('...')
#2 {main}
thrown in /www/wwwroot/v.cechi360.com/inc/common/function.php on line 80