update page now

Voting

The Note You're Voting On

@runspired
13 years ago
I don't think this is a bug, just an unexpected behavior.  While building an API I discovered that passing INT 0 instead of STRING '0' into a prepared statement caused my script to run out of memory and produce a 500error on the webpage.

A simplified example of this issue is below: ($_DB is a global reference to a mysqli connection)

<?php
function getItem( $ID ) {

     $_STATEMENT = $_DB->prepare("SELECT item_user, item_name, item_description FROM item WHERE item_id = ?;");

     $_STATEMENT->bind_param( 'i' , $ID );

     $_STATEMENT->execute();
     $_STATEMENT->store_result();

     $_STATEMENT->bind_result( $user , $name , $description);
     $result = $_STATEMENT->fetch();

     $_STATEMENT->free_result();
     $_STATEMENT->close();

     return $result;
}

getItem(0); //fails!
getItem('0'); //works!

?>

The best I can guess is that an INT 0 gets translated as BOOLEAN , and if this is indeed the case it should be documented above, but all efforts to get error information (via the php script) have failed.

<< Back to user notes page

To Top