You are here: Re: Confused by mysqli « PHP Programming Language « IT news, forums, messages
Re: Confused by mysqli

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-

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация