[英]CodeIgniter Random PHP Fatal error: Call to a member function … on a non-object in … mysqli_driver.php
I find many posts that are close to this but none are the same. 我发现有很多贴子与此相似,但都不相同。 I have a heavily used CodeIgniter app that has maybe a couple dozen, totally random, fatal errors logged to the error log per day. 我有一个使用率很高的CodeIgniter应用程序,每天可能有几十个完全随机的致命错误记录到错误日志中。
PHP Fatal error: Call to a member function real_escape_string() on a non-object in /system/database/drivers/mysqli/mysqli_driver.php PHP致命错误:在/system/database/drivers/mysqli/mysqli_driver.php中的非对象上调用成员函数real_escape_string()
or 要么
PHP Fatal error: Call to a member function query() on a non-object in /system/database/drivers/mysqli/mysqli_driver.php PHP致命错误:在/system/database/drivers/mysqli/mysqli_driver.php中的非对象上调用成员函数query()
The member function is random. 成员函数是随机的。 Row(), Query(), real_escape_string(), num_rows(), etc. Row(),Query(),real_escape_string(),num_rows()等。
I added a log function to mysqli_driver.php that dumps a stack trace whenever it receives a non-object: 我在mysqli_driver.php中添加了一个日志函数,该函数会在接收到非对象时转储堆栈跟踪:
if(!is_object($this->conn_id))
// Dump stack
This tells me that the error is happening in random places in my app so I am assuming the problem is not in my code. 这告诉我错误是在应用程序中的随机位置发生的,因此我假设问题不在我的代码中。 That leaves my server configuration as the suspect. 剩下的就是我的服务器配置。 I can't find any smoking guns and I cannot reproduce the error. 我找不到任何吸烟枪,也无法重现该错误。
I'm grasping at straws here. 我在这里抓稻草。 Can anyone offer ideas on what else I can do to track this down? 谁能提供关于我可以采取哪些其他措施的想法?
UPDATE: Here are the configs I use. 更新:这是我使用的配置。 Main DB connection: 主数据库连接:
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'cfMaster',
'password' => 'somemasterpw',
'database' => 'cfMaster',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => FALSE
);
When connecting to an alternate DB: 连接到备用数据库时:
// $userDb array contains all of the connection details.
$firmDb = array( "firm_id" => $userDb[0]->firm_id,
"hostname" => $userDb[0]->hostname,
"username" => $userDb[0]->username,
"password" => $userDb[0]->password,
"database" => $userDb[0]->database,
"dbdriver" => "mysqli",
"pconnect" => FALSE );
$this->db = $this->load->database($firmDb, TRUE, TRUE);
~35K connections per hour. 每小时约35K个连接。 ~20 failures per day. 每天约20次失败。 All of my database connections work fine literally 99.99% of the time. 实际上,我所有的数据库连接在99.99%的时间内都可以正常工作。 Finding that 0.01% failure is my issue. 发现0.01%的失败是我的问题。
"non-object" means that the variable ($db) doesn't refer to an object. “非对象”表示变量($ db)不引用对象。 Did you assign it to your database class (eg, $db = new databaseClass();, or whatever the class you're using is named)? 您是否将其分配给数据库类(例如,$ db = new databaseClass();或您正在使用的类的任何名称)?
Replace 更换
$var = &new class(); with $var = new class();
it will work 它会工作
try to load database on your method and try 尝试在您的方法上加载数据库并尝试
function __construct(){
parent::__construct();
$this->load->database();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.