I have problem with php script.
The thing is that it shows me, that I am calling to a function of a non-object, but the object exists.
Script is:
if ($dcdt_sql['pdo']) {
try {
$dbh = new PDO(
'mysql:host='.$dcdt_sql[0].';dbname='.$dcdt_sql[3],
$dcdt_sql[1],
$dcdt_sql[2],
array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::ATTR_PERSISTENT => false
)
);
}
catch (PDOException $e) { die("PDO ERR: [".$e->getMessage()."]"); }
}
else { $dbh = DBManager::connect(); }
switch ($mode) {
case 'fetch_assoc':
if ($dcdt_sql['pdo']) {
try {
$sth = $dbh->prepare($sqlQuery)->execute();
$result = $sth->fetchAll(PDO::FETCH_ASSOC); // PROBLEM IS IN THIS LiNE
$return = $result;
}
catch (PDOException $e) { die("PDO ERR: [".$e->getMessage()."]"); }
}
else {
$result = $dbh->query($sqlQuery);
if (!is_object($result)) { die('DEBUG: Query error: ['.$sqlQuery.'] returned: ['.print_r($result,1).']'); }//DEBUG
while ($row = $result->fetch_assoc()) {
$list[] = $row;
}
$return = $list;
}
break;
Problem is where I commented it, but it should be an object whos function is called.
So I don’t get it.
Error I get:
Fatal error: Call to a member function fetchAll() on a non-object in /usr/local/www/apache22/data/centrs/dc_elec/report.lib.inc on line 102
Thank You in advance.
http://sg.php.net/manual/en/pdostatement.fetchall.php
Correct usage as dictated: