0
$db = new PDO("mysql:host=$dbHost;dbname=$db;charset=utf-8", $dbUser, $dbPass);
return $db;

# Get all users in pot
$stmt = $db->query('SELECT * FROM `currentPot`');
$currentPotArr = $stmt->fetchAll();

and I've got error like this :

[Fri Dec 11 07:57:35.260326 2015] [:error] [pid 2274] [client 89.64.51.139:32356] PHP Fatal error: Call to a member function fetchAll() on boolean in /home/admin/domains/csbox.pl/public_html/php/update.php on line 21,

referer: http://csbox.pl/

Why?

Php 5.6.16 Apache 2.4.17 DirectAdmin 1.49.1 MySQL 5.6.12

On the site also iv'e got an php/update.php 500 (Internal Server Error) error

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Jacek Jot
  • 81
  • 1
  • 7

2 Answers2

0

Your PDO statement and fetching results seems to be all right. one thing I noticed ,

$db = new PDO("mysql:host=$dbHost;dbname=$db;charset=utf-8", $dbUser, $dbPass); return $db;

why you writing "return $db". Does it is inside function? Just remove "return $db;" if it is not a fuction.

Yousaf
  • 36
  • 2
  • If that were the problem the line throwing the error wouldn't even be executed. – Gerald Schneider Dec 11 '15 at 13:31
  • it will through error, if you a call a function on non-object variable. see "Call to a member function fetchAll() on boolean" that mean $db was Boolean . its values can be TRUE. – Yousaf Dec 11 '15 at 13:35
  • True, but if the code returned in the return line the function wouldn't even be called. Obviously the provided code is not the full code. – Gerald Schneider Dec 11 '15 at 13:37
  • I agree with your statement. he probably need to paste full function in order to find out what really causing fatal error. – Yousaf Dec 11 '15 at 13:45
0

PDO::query() returns a PDOStatement object, or FALSE on failure.

Perhaps the query is returning false? (Your error: Call to a member function fetchAll() on boolean).

See: http://php.net/manual/en/pdo.error-handling.php

Progrock
  • 7,373
  • 1
  • 19
  • 25