// First, prepare the statement, using placeholders
$query = "SELECT * FROM tableName";
$stmt = $this->connection->prepare($query);
// Execute the statement
$stmt->execute();
var_dump($stmt->fetch(PDO::FETCH_ASSOC));
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
echo "Hi";
// Export every row to a file
fputcsv($data, $row);
}
Is this correct way to do and if yes than why do I get false value for var_dump and than it does not go into while loop and does not write into csv file.
Any suggestions ?
One thing that is missing is that you first need to open the csv file:
then you can put data into it:
As for the var_dump printing out false, you would have to provide more information about what objects you are actually using I think. (ie: what is $this->connection ?)
I don’t know if this will help, but try to do it without the $this->connection: