Posted by David Haynes on 07/05/06 10:47
Dodger wrote:
[snip]
>
> $query = <<<EOF
> SELECT *
> FROM cities
> WHERE Country = ?
> EOF;
>
> $statement = $dbh->prepare($query);
> $statement->bind_param('USA');
> $statement->execute();
> $statement->store_result();
>
> $cities = array();
> $i = 0;
> while ($city = $statement->fetch_assoc()) {
> $cities[$i] = $city;
> $i++;
> }
The store->result() method returns a mysqli_result type.
You need to use the mysqli_type for the fetch_assoc() method.
So your code would look like:
$statement->execute();
$result = $statement->store_result();
$cities = array();
while( $city = $result->fetch_assoc() ) {
$cities[] = $city; // you don't need to supply the $i++ index this way
}
$result->free(); // don't forget to free the result memory
-david-
[Back to original message]
|