gpt4 book ai didi

php - 错误 MysqliDb::$_paramTypeList

转载 作者:行者123 更新时间:2023-11-30 00:51:20 24 4
gpt4 key购买 nike

我用这个https://github.com/ajillion/PHP-MySQLi-Database-Class

这是我的课

require_once ('class/MysqliDb.php');

class Foo {

private $db;

public function __construct()
{
$this->db = MySqliDb::getInstance();
}
}

public function register($password, $email) {

$password = @sha1($password);

$query = $this->db
->where('email', $email)
->get('users');

if (count($query) == 0)
{

$insertData = array(
'email' => $email,
'password' => $password
);

if($this->db->insert('users', $insertData)){
return true;
}

}else{
return FALSE;
}
}

我保存在 Db 中(如果 count($query) == 0),但我也收到此错误

( ! ) Notice: Undefined property: MysqliDb::$_paramTypeList in /.../class/MysqliDb.php on line 356

如果我不写这个查询

$query = $this->db
->where('email', $email)
->get('users');

我没有错误。我可以在单个函数中进行多重查询吗?我怎么会出现这个错误 MysqliDb::$_paramTypeList

最佳答案

问题出在MysqliDb.php中的reset()函数

protected function reset()
{
$this->_where = array();
$this->_bindParams = array(''); // Create the empty 0 index
unset($this->_query); //<-- unsetting variables which could be resused
unset($this->_whereTypeList);
unset($this->_paramTypeList);
}

reset() 在每个执行方法之后运行,它取消设置 _paramTypeList 属性,而不是仅仅重新初始化它。因此,如果您使用同一数据库对象运行第二个查询,则不再定义 _paramTypeList 属性。

您可以通过编辑reset() 函数来将这些变量重新初始化回 null 来解决此问题:

protected function reset()
{
$this->_where = array();
$this->_bindParams = array(''); // Create the empty 0 index
$this->_query = null;
$this->_whereTypeList = null;
$this->_paramTypeList = null;
}

关于php - 错误 MysqliDb::$_paramTypeList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20941107/

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