zhtway
zhtway

Reputation: 283

fetch array php

I am working on fetching data from a table in PHP with the following code. How can I copy all rows directly into an array? I tried fetch_array() instead of fetch() but it was also not successful.

$stmt = $this->db->prepare($sql); 
$stmt->execute();
$stmt->bind_result($aID, $sID);

while ($stmt -> fetch()) { 
    echo $aID . " ". $sID . "<br>";
}           

Upvotes: 0

Views: 2154

Answers (3)

Daryl Gill
Daryl Gill

Reputation: 5524

If using PDO

the Fetch_column is what you are looking for

$stmt = $this->db->prepare($sql); 
        $stmt->execute();
        $stmt->bind_result($aID, $sID);
    $Arrays = $stmt ->fetchAll(PDO::FETCH_COLUMN);

Upvotes: 1

Rob
Rob

Reputation: 12872

$array = $stmt->fetchAll(PDO::FETCH_ASSOC);

Upvotes: 0

Jason McCreary
Jason McCreary

Reputation: 73031

How can I copy all rows directly into array?

Upvotes: 0

Related Questions