为什么mysqli_query()坏了? [mysqli_query():无法获取mysqli] [英] Why is mysqli_query() breaking? [mysqli_query(): Couldn't fetch mysqli]

查看:187
本文介绍了为什么mysqli_query()坏了? [mysqli_query():无法获取mysqli]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mysqli_query包含在我的代码中的以下封装函数中:

Mysqli_query is contained in the following encapsulating function in my code:

function QueryDatabase($query){
error_log("Database Line 134: " . memory_get_usage(true));
$QueryResult = NULL;

    switch($this->RDBType){
        case 'MySQL':
            error_log('MySQLi link IS Valid?:'); error_log(boolval($this->link));
            error_log(get_class($this->link));
            error_log("Database Line 139: " . memory_get_usage(true));
            error_log("Performing Query: '" . $query . "'");
            $QueryResult = mysqli_query($this->link, $query);
            error_log("Result: " . gettype($QueryResult));
            error_log("Database Line 141: " . memory_get_usage(true));
            break;
        case 'PostGreSQL':
        default:
            break;
    }
error_log("Database Line 147: " . memory_get_usage(true));  
return $QueryResult;
}

PHP错误日志如下:

The PHP error log looks like this:

[2016年5月11日17:04:00欧洲/柏林]数据库第134行:262144

[11-May-2016 17:04:00 Europe/Berlin] Database Line 134: 262144

[2016年5月11日17:04:00欧洲/柏林] MySQLi链接是否有效?:

[11-May-2016 17:04:00 Europe/Berlin] MySQLi link IS Valid?:

[2016年5月11日17:04:00欧洲/柏林] 1

[11-May-2016 17:04:00 Europe/Berlin] 1

[2016年5月11日17:04:00欧洲/柏林] mysqli

[11-May-2016 17:04:00 Europe/Berlin] mysqli

[2016年5月11日17:04:00欧洲/柏林]数据库第139行:262144

[11-May-2016 17:04:00 Europe/Berlin] Database Line 139: 262144

[11-May-2016 17:04:00欧洲/柏林]执行查询:'SELECT * FROM 扫描 INNER JOIN土地 在scans.scansId = landlot.scansId上 内连接区 在scans.scansid = district.scansId上 INNER JOIN街道名称 在scans.scansid = streetname.scansId的位置上= 1;'

[11-May-2016 17:04:00 Europe/Berlin] Performing Query: 'SELECT * FROM scans INNER JOIN landlot on scans.scansId = landlot.scansId INNER JOIN district on scans.scansid = district.scansId INNER JOIN streetname on scans.scansid = streetname.scansId WHERE Lot = 1;'

[2016年5月11日17:04:00欧洲/柏林] PHP警告:mysqli_query(): 无法在中获取mysqli I:\ xampp \ htdocs \ GLS_DBSearchProject \ Database.php,第145行

[11-May-2016 17:04:00 Europe/Berlin] PHP Warning: mysqli_query(): Couldn't fetch mysqli in I:\xampp\htdocs\GLS_DBSearchProject\Database.php on line 145

[2016年5月11日17:04:00欧洲/柏林]结果:NULL

[11-May-2016 17:04:00 Europe/Berlin] Result: NULL

[2016年5月11日17:04:00欧洲/柏林]数据库第141行:262144

[11-May-2016 17:04:00 Europe/Berlin] Database Line 141: 262144

[2016年5月11日17:04:00欧洲/柏林]数据库第147行:262144

[11-May-2016 17:04:00 Europe/Berlin] Database Line 147: 262144

[2016年5月11日17:04:00欧洲/柏林] PHP注意:尝试获取 非对象的属性 I:\ xampp \ htdocs \ GLS_DBSearchProject \ DatabaseSearch.php在第86行

[11-May-2016 17:04:00 Europe/Berlin] PHP Notice: Trying to get property of non-object in I:\xampp\htdocs\GLS_DBSearchProject\DatabaseSearch.php on line 86

[2016年5月11日17:04:00欧洲/柏林]数据库第134行:262144

[11-May-2016 17:04:00 Europe/Berlin] Database Line 134: 262144

[2016年5月11日17:04:00欧洲/柏林] MySQLi链接是否有效?:

[11-May-2016 17:04:00 Europe/Berlin] MySQLi link IS Valid?:

[2016年5月11日17:04:00欧洲/柏林] 1

[11-May-2016 17:04:00 Europe/Berlin] 1

[2016年5月11日17:04:00欧洲/柏林] mysqli

[11-May-2016 17:04:00 Europe/Berlin] mysqli

[2016年5月11日17:04:00欧洲/柏林]数据库第139行:262144

[11-May-2016 17:04:00 Europe/Berlin] Database Line 139: 262144

[11-May-2016 17:04:00欧洲/柏林]执行查询:'SELECT * FROM 扫描 INNER JOIN土地 在scans.scansId = landlot.scansId上 内连接区 在scans.scansid = district.scansId上 INNER JOIN街道名称 在scans.scansid = streetname.scansId上,手数= 1限制10偏移0;'

[11-May-2016 17:04:00 Europe/Berlin] Performing Query: 'SELECT * FROM scans INNER JOIN landlot on scans.scansId = landlot.scansId INNER JOIN district on scans.scansid = district.scansId INNER JOIN streetname on scans.scansid = streetname.scansId WHERE Lot = 1 LIMIT 10 OFFSET 0;'

[2016年5月11日17:04:00欧洲/柏林] PHP警告:mysqli_query(): 无法在中获取mysqli I:\ xampp \ htdocs \ GLS_DBSearchProject \ Database.php在第145行

[11-May-2016 17:04:00 Europe/Berlin] PHP Warning: mysqli_query(): Couldn't fetch mysqli in I:\xampp\htdocs\GLS_DBSearchProject\Database.php on line 145

[2016年5月11日17:04:00欧洲/柏林]结果:NULL

[11-May-2016 17:04:00 Europe/Berlin] Result: NULL

[2016年5月11日17:04:00欧洲/柏林]数据库第141行:262144

[11-May-2016 17:04:00 Europe/Berlin] Database Line 141: 262144

[2016年5月11日17:04:00欧洲/柏林]数据库第147行:262144

[11-May-2016 17:04:00 Europe/Berlin] Database Line 147: 262144

[2016年5月11日17:04:00欧洲/柏林] PHP致命错误:调用了 成员函数fetch_assoc()在非对象中 I:\ xampp \ htdocs \ GLS_DBSearchProject \ DatabaseSearch.php在第126行

[11-May-2016 17:04:00 Europe/Berlin] PHP Fatal error: Call to a member function fetch_assoc() on a non-object in I:\xampp\htdocs\GLS_DBSearchProject\DatabaseSearch.php on line 126

我真的很困惑为什么mysqli_query无法返回结果.在我的整个项目中,我已经多次使用QueryDatabase()函数,并且到目前为止没有遇到任何问题.我有一个PHPUnit测试,该测试表明我的QueryDatabase()函数似乎正常工作,所有其他迹象均指向在mysqli_query()函数调用期间发生的问题.

I'm really confused as to why mysqli_query is failing to return a result. I have used my QueryDatabase() function numerous times throughout my project and have encountered no issues until now. I have a PHPUnit test which shows that my QueryDatabase() function appears to be working properly, and all other signs point to the problem occurring during the mysqli_query() function call.

我已经广泛检查以确保数据库链接($ this->链接中包含的mysqli对象)有效并且指向适当的数据库.我还通过手动复制并将其粘贴到mysql查询浏览器中来确保我的查询正常工作.

I have extensively checked to make sure that the database link (the mysqli object contained within $this->link) is valid and points to the appropriate database. I have also checked to ensure that my query works as expected by manually copying and pasting it into the mysql query browser.

如果我的查询有效并且我的数据库链接有效,为什么mysqli_query()会失败?

If my query is valid AND my database link is valid why could mysqli_query() be failing?

我从未关闭任何数据库连接.所以数据库连接不应该关闭

I never closed any of my database connections. So the database connection should not be closed

推荐答案

您的日志没有任何问题.

There is nothing wrong with your logs.

实时mysqli实例并不意味着存在实时mysql连接.与PDO不同,您可以关闭mysql连接,但是可以使用mysqli对象.因此错误消息说:

A live mysqli instance doesn't mean there is a live mysql connection. Unlike PDO, you can close mysql connection but have a mysqli object all right. So the error message says:

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$conn = new mysqli('localhost','root','','test');
$conn->query("SELECT 1");
$conn->close();
var_dump(get_class($conn));
$conn->query("SELECT 1");

将为您提供预期的输出:

will give you expected output:

字符串(6)"mysqli"
警告:mysqli :: query():无法在第10行的mysqli.php中获取mysqli

string(6) "mysqli"
Warning: mysqli::query(): Couldn't fetch mysqli in mysqli.php on line 10

您必须找到代码关闭连接的位置并进行修复.

You have to find the place where your code is closing connection and fix it.

这篇关于为什么mysqli_query()坏了? [mysqli_query():无法获取mysqli]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆