Re: Bizarre array create error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ken Tozier wrote:
Hi

I'm trying to assign two fields of an object returned from a MySQL query and have stumbled upon the most bizarre PHP bug where I can't create two arrays in succession.

Here's the MySQL query with two dummy fields to be filled in later

select *, 0 as dummy_1, 0 as dummy_2 from table

Here's how I'm grabbing the query results

$result            = array();
while ($row = mysql_fetch_object($query_result))
{
    $result[]    = $row;
}

Once that's done, I try to set two of the rows to arrays like this

$result-> dummy_1    = array(1, 2, 3, 4);
$result-> dummy_2    = array('a', 'b', 'c', 'd');

If I comment out either of the above lines, the script works but with both uncommented, it seems to drop dead. It doesn't even return an error.
Is this all of your code? Do you have some sort of output display for your results? Does PHP generally return errors to the browser? When I tried your code above with a test table with four data fields I got this error:
*
Warning*: Attempt to assign property of non-object in */usr/local/apache/htdocs/test-script.php* on line *14 **Warning*: Attempt to assign property of non-object in */usr/local/apache/htdocs/test-script.php* on line *15

*Then I re-read your code and realized that you made $row an object not $result, it's just an array. Changing this:

$result->dummy_1 = array(1, 2, 3, 4); $result->dummy_2 = array('a', 'b', 'c', 'd');
to this:

$row->dummy_1 = array(1, 2, 3, 4); $row->dummy_2 = array('a', 'b', 'c', 'd'); Yielded no errors for me what so ever. However, since it's unclear on what you are doing with this data I can't vouch that it's actually what you need. Double check your display_errors setting in your php.ini and make sure it's set to On. Because you're either not giving us all the code to work with and something else is happening and that's why you don't get the error but not your desired result or you're not displaying the errors.

I've been doing assignments like the above for 3 years and never had a problem and in fact the exact same function works perfectly in another script.This one has me utterly stumped.

Does that script run on the same machine? If it's on another machine is that machine running the same version? I ran this on a server with Apache 2.2.4, PHP 5.2.3 and mySQL 5.0.18. Have you referenced that other script to make sure that it *is* exactly the same?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux