Re: [PHP-PEAR] MYSQL_ASSOC & DB_FETCHMODE & more
[email protected] ("Stig S. Bakken")
| Newsgroups | php.pear |
|---|---|
| Organization | Fast Search & Transfer |
| Message-ID | <[email protected]> |
> Robert Kelly wrote:
>
> Howdy!
>
> I'd like to say we're thinking of using PEAR here at Insight.com and
> leveraging it. Hopefully will be giving our code back to the
> community as well.
>
> Where is MYSQL_ASSOC defined? I cannot find this definition
> anywhere... it's not in php.ini or the DB.php and DB/*. at least, it
> doesn't show up on a grep.
>
> Method getAssoc calls the fetchRow function with the
> DB_FETCHMODE_[PARAM]. It passes mysql_fetch_array the MYSQL_ASSOC
> value.
>
> if ($fetchmode & DB_FETCHMODE_ASSOC) {
> $row = mysql_fetch_array($result); //<- I am seeking this
> #$row = mysql_fetch_array($result, MYSQL_ASSOC); //<-not this
> } else {
> $row = mysql_fetch_row($result);
> }
>
> So, question one is where is the MYSQL_ASSOC (its defaulting to 1)
> set. Question 2, if I am wanting an associative array (like the line
> above), shoudl I be setting DB_FETCHMODE_ to something different?
DB_FETCHMODE_ASSOC is a constant. A lot of DB methods have a
"fetchmode" parameter where you can use either DB_FETCHMODE_ASSOC or
DB_FETCHMODE_ORDERED.
For example:
$sth = $dbh->query("SELECT foo, bar FROM table");
$row = $sth->fetchRow(DB_FETCHMODE_ASSOC);
The $row you get here will be indexed by column name. If you remove the
fetchmode parameter or change it to DB_FETCHMODE_ORDERED, $row will have
numerical indexes.
MYSQL_ASSOC is defined in PHP itself.
- Stig