Stanislas Piotrowski Stanislas Piotrowski - 1 year ago 53
SQL Question

fetchColumn error on PDO while trying to get number of rows

I'm trying to move to PDO.

I want to do a classic query for checking number of rows, in mysql I would have done

but I've read somewhere that in PDO it does not work.

So I've tried with a fetch column using the following code :

global $bdd;
$login = $bdd->query("SELECT
FROM spb_clients_acces_compte,
WHERE spb_clients_acces_compte.spb_clients_acces_compte_e_mail = '{$email}'
AND spb_clients_acces_compte.spb_clients_acces_compte_pwd_md5 = '{$pass}'
AND spb_clients_acces_compte.spb_clients_acces_compte_admin = 1");
$reponse = $bdd->fetchColumn();
if ($reponse == 0):

elseif ($reponse == 1):


This return to me :

( ! ) Fatal error: Call to undefined method PDO::fetchColumn() in C:\wamp\www\spb2016\admin\core\login.php on line 20

Line 20 is :
$reponse = $bdd->fetchColumn();

I've tried many things with no success

Anykind of help will be much appreciated.

Answer Source

First of all, you need to add a column to your COUNT function. COUNT is a mysql function that returns the number of whatever parameter you pass it, so COUNT(id) would work.

Second, you must use the PDOStatement in order to fetch results. Replace

$reponse = $bdd->fetchColumn();


$reponse = $login->fetchColumn();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download