gpt4 book ai didi

php - 查询在脚本中返回空集,适用于 PHPMyAdmin 和本地版本

转载 作者:行者123 更新时间:2023-11-29 03:32:54 24 4
gpt4 key购买 nike

这已经困扰我好几个小时了。这段代码在我的本地机器上运行完美,查询在 phpmyadmin 等中执行。

我有以下代码:

 <?php

class db {
public $server = 'localhost';
public $user = '***';
public $passwd = '***';
public $db = '***';
public $dbCon;

function __construct(){
$this->dbCon = mysqli_connect($this->server, $this->user, $this->passwd, $this->db);
}

function __destruct(){
mysqli_close($this->dbCon);
}

private function getFileTree($catID) {

$sql = "SELECT
*
FROM
table_name
WHERE
cat_id = ".$catID;

$results = mysqli_query($this->dbCon, $sql);


return $results;
}



}

$db = new db();

$cat_id = 1;

$data = $db->getFileTree($cat_id);

echo json_encode($data);


?>

我很困惑,因为查询看起来不错,它在 PHPMyadmin 中运行,并且脚本在我的本地版本上运行良好,但一旦我移至服务器,它只会返回一个空数组。我唯一能想到的是它与服务器上的旧 php 版本有关,但它似乎仍然应该工作,我所有其他查询都工作正常。

另外,当我 var_dump $results 时,在数据库中尝试一个 cat_id 时,我得到以下信息:

NULL NULL NULL NULL NULL array(1) { [""]=> NULL }

以及当我尝试其他 cat_id 时的以下内容:

object(mysqli_result)#3 (5) { ["current_field"]=> int(0) ["field_count"]=> int(6) ["lengths"]=> NULL ["num_rows"]=> int(24) ["type"]=> int(0) } [null]

最佳答案

$subjectID 的值是多少?。看来你必须给 $catID 而不是 $subjectID

关于php - 查询在脚本中返回空集,适用于 PHPMyAdmin 和本地版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27716468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com