I am trying to create a universal method/function on php which uses any select statement with a where clause. However, something is not right. Can you give me a hand?
Example of using data:
DB inherit PDO class.
$db=new DB;
$db->select("SELECT count(*) FROM `login` WHERE Email='?'",
"papa1980@gmail.com");
Here is function
public function select($sqlString,...$bindParameters)
{
$stmt=$this->prepare($sqlString);
foreach($bindParameters as $key=>$bindParameter)
{
$stmt->bindParam(($key+1),$bindParameter);
echo '<pre>' . print_r($stmt, true) . '</pre>';
}
echo '<pre>' . print_r($bindParameters, true) . '</pre>';
if($stmt->execute())
{
echo "execution was succesful";
}
echo '<pre>' . print_r($stmt->fetchAll(), true) . '</pre>';
}
Output
PDOStatement Object
(
[queryString] => SELECT count(*) FROM login
WHERE Email='?'
)
Array ( [0] => papa1980@gmail.com )
execution was succesful
Array ( [0] => Array ( [count(*)] => 0 [0] => 0 ) )
Why is it returning 0? I use
SELECT count(*) FROM `login` WHERE Email='papa1980@gmail.com'
in mysql and it returns 1. Something is not correct in my php code.