belgampaul Posted March 23, 2007 Share Posted March 23, 2007 Hello, folks I see sometimes very weird behaviour of PHP like in the case I'll try to describe. I've written a class Cars that is a holder class for <code>Car</code> and it's designed to fetch Car records from out DB2 database. And it works fine until I return the $result to the calling function. I can use my $result to print html table but only inside the getAll method. When the $result is returned to the calling function the $result source is no more working properly as expected by me though the resource id stays the same. Finally I get a warning: Warning: db2_fetch_array() [function.db2-fetch-array]: Column information cannot be retrieved . Though calling the same db2_fetch_array() function within the Cars::getAll method (see code below) works as expected (again by me but I got the result from the query). I have no clue why this warning happens in the first place. Probably I miss something. Should I do something special to get the $result source in the calling function as it is in the method where it's created? Any advice is welcome. class Cars{ public static function getAll($date){ $conn = MyDBAdapter::getConnection(); $sql = "Select * from Cars"; $result = db2_exec($conn, $sql); return $result; } } calling method getAll method from index.php $result = Cars::getAll('20060606'); db2_fetch_array($result); ..... I stripped down the example to make it short and simple. If you feel like you need more details, please ask. Our PHP Configuration Zend Core Version 1.6.0 PHP Version 5.1.6 Zend Engine Version 2.1.0 Server API apache2handler PHP Configuration File /usr/local/Zend/core/etc/php.ini Thanks in advance Quote Link to comment Share on other sites More sharing options...
belgampaul Posted March 23, 2007 Author Share Posted March 23, 2007 lol, nobody's even reading my post. the title is too frightening. it's not a newbie kind of problem. i'm struggling with it since 3 hours. Making all possible tests. Please help if you can Quote Link to comment Share on other sites More sharing options...
belgampaul Posted March 23, 2007 Author Share Posted March 23, 2007 Is there something wrong with the scope? Still need help. Quote Link to comment Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 Are you defining the class IE: Cars = new Cars(); $result = Cars::getAll('20060606'); db2_fetch_array($result); Quote Link to comment Share on other sites More sharing options...
belgampaul Posted March 23, 2007 Author Share Posted March 23, 2007 Are you defining the class IE: Cars = new Cars(); $result = Cars::getAll('20060606'); db2_fetch_array($result); I don't quite understand the question. But if you ask wether I declare an instance of Cars, the answer is no. I don't need to declare a cars object 'coz I call a static method. I'm still a bit confused about your question Quote Link to comment Share on other sites More sharing options...
belgampaul Posted March 23, 2007 Author Share Posted March 23, 2007 this code works // static function of the Cars class function public static getAll(){ $result = be_bordet_db_BORPRD::executeSelect($conn,$query); //getTable calls db2_fetch_array() echo php_db_ui_HTML::getTable($result); } and this doesn't with the following Warning: Warning: db2_fetch_array() [function.db2-fetch-array]: Column information cannot be retrieved in /usr/local/Zend/apache2/htdocs/transpat/lib/php/db/ui/HTML.php on line 49 So I don't get any results from the database. function public static getAll(){ $query = $select.$where; $result = be_bordet_db_BORPRD::executeSelect($conn,$query); return $result; } //index.php $result = Cars::getAll(); echo php_db_ui_HTML::getTable($result); What's the trick? Quote Link to comment Share on other sites More sharing options...
belgampaul Posted March 23, 2007 Author Share Posted March 23, 2007 Anybody??? just react once. write something like: "OK. The logic is right. It should work." or "Dude, you're screwed up. You pass a value but then you use a reference. It's 'coz you're stupid. Read up on PHP" I would be very grateful just to know that somebody thinks I'm wrong, right or he/she comes up with his solution. Quote Link to comment Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 Maybe instead of sing the * in the query try listing out the column names? Quote Link to comment Share on other sites More sharing options...
belgampaul Posted March 23, 2007 Author Share Posted March 23, 2007 Maybe instead of sing the * in the query try listing out the column names? it's a nice try. though i select only needed columns and i've just tested this in the context of index.php $conn = be_bordet_db_BORPRD::getDatabaseConnection(); $result = be_bordet_db_BORPRD::executeSelect($conn, 'SELECT* FROM cars''); echo php_db_ui_HTML::getTable($result); it drives me crazy. it seems to me a bug in php, but it can be that I don't know php deeply enough to figure out what the heck happens. Quote Link to comment Share on other sites More sharing options...
belgampaul Posted March 23, 2007 Author Share Posted March 23, 2007 Not finished my post. So i tried the following code int index.php context and it works nicely as it should. But note that we're in the file. When I use 2 files a Class and an index.php index.php doesn't seem to get the resource though the var_dump in Cars::getAll and var_dump in index.php return resource id 13 //Cars calls be_bordet_db_BORPRD::getDatabaseConnection() to get $conn (connection to the DB) $conn = be_bordet_db_BORPRD::getDatabaseConnection(); //Cars calls be_bordet_db_BORPRD::executeSelect that calls db2_exec to get the $result $result = be_bordet_db_BORPRD::executeSelect($conn, 'SELECT* FROM cars''); echo php_db_ui_HTML::getTable($result); Quote Link to comment Share on other sites More sharing options...
belgampaul Posted March 23, 2007 Author Share Posted March 23, 2007 Would you exepect my code work at all? I have to spam a bit, to stay on top. Quote Link to comment Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 You don't have to spam at all, if anything that will make people not want to help you. If someone has the answer, chances are they will help. If not than sorry bud do some google searching maybe someone already encountered the problem and fixed it. If not do some trial and error tests. Just remember to KISS - Keep It Simple Stupid when you do your trail-error. Quote Link to comment Share on other sites More sharing options...
belgampaul Posted March 23, 2007 Author Share Posted March 23, 2007 You don't have to spam at all, if anything that will make people not want to help you. If someone has the answer, chances are they will help. If not than sorry bud do some google searching maybe someone already encountered the problem and fixed it. If not do some trial and error tests. Just remember to KISS - Keep It Simple Stupid when you do your trail-error. yeah, good advice. before posting here I spend more than an hour testing this stuff. it doesn't make any sense to me their warning. Just to keep it simple, a week ago I got an IBM support guy 2 hours on the phone and remotely connected to our system to figure out why Apache Reverse Proxy wouldn't let us use htdocs directory. And his answer was: "I would like to know the answer myself". If I KISS too much, no classes and usual php example spaghetti code, it works great. But I'm not going even to start thinking about not using classes. If nobody confirms that the code I posted is utterly wrong, then I consider it a bug. And it looks like php bug unless there's a little surprise from the ibm driver or the db2 udb. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.