I use this https://github.com/ajillion/PHP-MySQLi-Database-Class
this is my my 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;
}
}
I save in Db (if count($query) == 0
) but I also receive this error
( ! ) Notice: Undefined property: MysqliDb::$_paramTypeList in /.../class/MysqliDb.php on line 356
if I do not write this query
$query = $this->db
->where('email', $email)
->get('users');
I Haven't error. Can I Do multi Query in the single function ? And how i have this error MysqliDb::$_paramTypeList
The problem lies in the reset() function in MysqliDb.php
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() is be run after every execution method and it unsets the _paramTypeList property instead of just re-initializing it. so if you go to run a 2nd query with the same db object the _paramTypeList property is no longer defined.
you could fix this by editing the reset() function to reinit those variables back to null instead:
protected function reset()
{
$this->_where = array();
$this->_bindParams = array(''); // Create the empty 0 index
$this->_query = null;
$this->_whereTypeList = null;
$this->_paramTypeList = null;
}