hello i have this code
public function query($sql, $params = array()) {
$this->_error = false;
if($this->_query = $this->_pdo->prepare($sql)) {
$x = 1;
if(count($params)) {
foreach($params as $param) {
$this->_query->bindValue($x, $param);
$x++;
}
}
if($this->_query->execute()) {
$this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount();
} else {
$this->_error = true;
}
}
return $this;
}
and when i run it, it's says that i have error in line
$this->_query->bindValue($x, $param);
The error message says Catchable fatal error: Object of class __PHP_Incomplete_Class could not be converted to string in any help please thank you
EDIT
var_dump of $params
array(1) {
[0]=> object(__PHP_Incomplete_Class)#1 (6) {
["__PHP_Incomplete_Class_Name"]=> string(4)
"User" ["_db":"User":private]=> object(__PHP_Incomplete_Class)#2 (2) {
["__PHP_Incomplete_Class_Name"]=> string(2) "DB"
["connection"]=> NULL
}
["_sessionName":"User":private]=> string(4) "user"
["_cookieName":"User":private]=> string(4) "hash"
["_data":"User":private]=> object(stdClass)#3 (7) {
["id"]=> string(3) "144"
["username"]=> string(5) "admin"
["password"]=> string(64) "0611affa6664e471b939cd3197b49e0c3b47d146fc12a472c4275dbd85a7cd67"
["salt"]=> string(32) "458a0dbfbd9bdca381e50b8d753329ea"
["name"]=> string(12) "Artur Papyan"
["joined"]=> string(19) "2013-11-29 07:41:54"
["group"]=> string(1) "1"
}
["_isLoggedIn":"User":private]=> bool(true)
}
}
The error says it clear: $params
contains at least an __PHP_Incomplete_Class
object that obviously can not be converted to a string to fill your query with.
The reason why you are obtaining __PHP_Incomplete_Class
objects is due to an unserialization of a session-stored object which class hasn't been loaded previously. So you have to include your session-stored classes before the session start. If you want my advice, autoloading is the best way to load clases thus you can forget of include
/require
statements at all. You can find out more info here: http://www.php.net/manual/en/language.oop5.autoload.php