NYCPHP Meetup

NYPHP.org

[nycphp-talk] mysqli exception problem

Flavio daCosta nyphp at n0p.net
Tue Nov 6 01:29:14 EST 2007


On 11/05/2007 08:34 PM, Michael Southwell wrote:
> One last question: when affected_rows returns -1 (according to the docs)
> it "indicates that the query returned an error." My example demonstrates
> this by throwing an exception here:
>   if ( $demo -> affected_rows == -1 ) throw new Exception ( "error
> trying to find wines with name “" . $param . '”'  );
> 
> Where is the error that the query returned?  It's not in $demo -> error.

Ok so, afaik, the affected_rows are only going to report if it is an
'UPDATE, DELETE, or INSERT' query, otherwise if it is a SELECT query, it
will show -1 for affected_rows and ->error will be empty.

It may be difficult to make a properly prepared SELECT statement error
with a /bad/ bound parameter, ymmv.

If you want the row_count from a SELECT query you will want to look at
->store_result (<http://php.net/mysqli_stmt_store_result>)

disclaimer: I don't claim to be authoritative on mysqli (actually kinda
have a favoritism to postgres :-P,) although I feel my advise is
somewhat sound. As all advice, take it with a grain of salt and if I'm
wrong, I'm sure someone will speak up...

flav



More information about the talk mailing list