My DB2 class has a prepare function:
public function prepare()
{
if (FALSE === ($this->stmt = db2_prepare($this->conn, $this->sql)))
{
throw new Exception($this->get_error());
}
return $this;
}
Some mysterious query is causing a warning in the php error log:
[26-Jan-2012 11:17:32] PHP Warning: db2_prepare(): Statement Prepare Failed in /<path to file>/Db2.php on line 178
db2_prepare is not returning FALSE. Otherwise, an exception would be thrown, and I would get a backtrace.
Am I am not properly testing the db2_prepare's return value to catch legitimate errors/warnings, or does db2_prepare have a bug?
This is running on the Zend Server stack on i5/iseries/as400.
A workaround in this situation would be a try catch block that generates exceptions on warnings. Not sure how that would work, and that sounds like another post to me.
Also, @ is not an option here. It's generating a warning for a reason. I prefer not to stick my head in the sand.
Update: I finally tracked down the query. It was a badly formed insert statement. Even though the prepare failed and generated an error, a valid statement resource was returned and the script continued with generating an exception. I was using exec to call the script that contained the bad INSERT, but I did not return the output of the script which is why I never saw the error.
It still seems buggy to me, but I don't have time to pursue it further.