I wasn't sure it was bug report worthy, so I decided to post it and find out
if this is a feature or a bug.

I have been crafting my own database abstraction layer, and in doing so
create an array of the results of a query.

So, for instance:

antQuery("select UNIX_TIMESTAMP() as utime, NULL as col2");

would (there's tons more to this function) return:

$data[0][0] = 980931929;
$data[0][utime] = 980931929;
$data[0][1] = "";
$data[0][col2] = "";

The first array is the row of the results, starting with, in this case, 0.
Then the second array is both the numeric and associative array values of
the returned data set.

NOW...I figured I'd just use mysql_fetch_array, which should give my both
numeric and associative keys to my data, but what happens is that
mysql_fetch_array() does not return the associative key for NULL values.

This annoyed me, so I ended up having to combine mysql_fetch_row() and
mysql_fetch_assoc() to get what I desired.

I set up a testbed, and here are the results.

---

Query: select UNIX_TIMESTAMP() as utime, NULL as col2



Using mysql_fetch_array( , MYSQL_BOTH)

Array
(
    [0] => 980933202
    [utime] => 980933202
    [1] => 
)

Using mysql_fetch_assoc()

Array
(
    [utime] => 980933202
    [col2] => 
)

Using mysql_fetch_row()

Array
(
    [0] => 980933202
    [1] => 
)

Using mysql_fetch_row() with mysql_fetch_assoc()

Array
(
    [utime] => 980933202
    [col2] => 
    [0] => 980933202
    [1] => 
)

--

I honestly can't imagine that this is a feature. Why would you not label a
null field's column name? In numerous cases, a null field is just as or more
important than a filled one.

The comments at http://php.net/manual/en/function.mysql-fetch-array.php
don't seem to tell me much except that that is how it's supposed to work.

I am running "Apache/1.3.17 (Unix) mod_ssl/2.8.0 OpenSSL/0.9.5a DAV/1.0.2
PHP/4.0.4pl1" on RH 7.

It's not the version of Apache either. It was the same with 1.3.14.

-

In the end, I guess my question is this: If mysql_fetch_array() by itself
will not return associative names for NULL characters, certainly
mysql_fetch_array( , MYSQL_BOTH) should.

Can this be changed?

I have a sneaking suspicion that I'm missing something here, but I felt it
should at least be asked.

Thanks!

  Mark J. Hershenson
  [EMAIL PROTECTED]
  http://www.green-ant.com/


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to