Jump to content

Weird warning: db2_fetch_array() [function.db2-fetch-array]: Fetch Failure


belgampaul

Recommended Posts

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 :o

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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  :D

//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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.