BeBot - An Anarchy Online and Age Of Conan chat automaton

Development => Coding and development discussion => Topic started by: Xenixa on May 13, 2006, 12:44:13 pm

Title: mysql_fetch_array Bug in PHP5 CLI processor.
Post by: Xenixa on May 13, 2006, 12:44:13 pm
I've discovered if your using PHP 5 there may be a bug with it. I know some of you may have seen this lately if you've moved to PHP5.
Fatal error: Cannot use string offset as an array in... etc. etc.

 For some unknown reason and I havn't figured out why yet, but from reading around in various PHP dev forums when you get a mysql_fetch_array result set back from a function used in a Foreach loop the array offsets get screwed up. One work around for it is if you're using PHP5 is to write another function that converts the returned mysql array to a defined array.

For an Example of defined array function I had to write to get rid of that string offset error see the TowerAttack.php I posted not long ago and look for function get_lcainfo($zone, $x, $y)

I'm currently looking at a way to re-write the function select($sql) in MySQL.php to build a defined array to return on the fly as a work around so I don't have to keep writing custom defined array functions for all my modules that use the select function in a for or foreach loop.
Title: Re: mysql_fetch_array Bug in PHP5 CLI processor.
Post by: Khalem on May 13, 2006, 02:15:49 pm
Any idea if this is limited to specific versions or resolved in latest php 5.1 releases?
Title: Re: mysql_fetch_array Bug in PHP5 CLI processor.
Post by: Xenixa on May 13, 2006, 02:25:52 pm
Well so far I've got the same Fatal error in PHP5.1.2 thru PHP5.1.4 concerning this issue. I've still yet to check bugs.php.net to see if it's been reported yet.
Title: Re: mysql_fetch_array Bug in PHP5 CLI processor.
Post by: Xenixa on May 13, 2006, 02:31:18 pm
Ok no time like the present and I don't know why I didn't do it sooner but it looks like a related issue.

http://bugs.php.net/bug.php?id=37001
Title: Re: mysql_fetch_array Bug in PHP5 CLI processor.
Post by: Malosar on May 13, 2006, 11:40:43 pm
Well I guess that explains the bug in my boss module.
Title: Re: mysql_fetch_array Bug in PHP5 CLI processor.
Post by: Nesi on May 24, 2006, 08:45:40 am
You must rewrite the MySQL.php to simply return the unaltered array you'd get from a normal query. The MySQL.php redos the original sql array before passing it back to the user. Which makes it unusable in any mysql_fetch_statements.

You can then for an example use
$members = $this -> bot -> db -> select_direct("SELECT * FROM members");
While ($member = mysql_fetch_assoc($members):
Echo $member["id"] . " - " . $member["nickname"];
Endwhile;

You can also explode the $member array so you'd get $id, $nickname and such.

Hope this made any sence :)
SimplePortal 2.3.7 © 2008-2024, SimplePortal