I'm trying to get the results from a Select statement using fetchALL() but nothing is working for some reason. Here is a sample of the code:
$vars = array(':name' => $_POST['name'], ':id' => $_POST['id']);
$stmt = $dbh->prepare("SELECT * FROM temp_table WHERE name=:name AND id=:id");
if($stmt->execute($vars)){
if($stmt->fetchColumn() > 0){
echo "Found";
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($result);
}else{
echo "Not found";
}
}else{
echo "Error";
}
The statement executes successfully, and it finds one column, like it should, and it echos "Found", but the array comes up as empty, it just comes up as array() Everything executes well, it's just that fetch, or fetchAll() always returns empty. Any help would be appreciated!
fetch_column()is fetching it to extract the column data. When you then callfetchAll()the data has already been fetched and there's no more.