Sometimes I feel like being one of the little who like PHP. But, one things which brings me to hell currently is the mysqli-extension. Not that it is not easy to use, there is one strange thing I’m fucked up with. If I read an Image-file via file_get_contents() and want to write it to a database, It’s sensible to use a BLOB-field. So far so fine. I guessed I have to do it this way:
$image_data = file_get_contents( "my_image.png" );
$database = new mysqli( "host", "user", "password" );
$database->select_db( "my_db" );
if( $statement = $database->prepare( "INSERT INTO my_table SET my_blob = ?" ) ) {
<strong>$statement->bind_param( "b", $image_data );</strong>
$statement->execute();
} else {
etc.mysqli::prepare(). So I guessed nothing wrong with it. But it seems to be wrong. If I use $statement->bind_param( "s", $image_data);, which means passing the value as a string, it works as expected. Is this a bug or can someone explain this strange behaviour to me?Filed under Code, MySQL, MySQL 5.0, mysqli, PHP & two comments & no trackbacks
Trackback specific URI for this entry
Gerd Riesselmann returns:
published on May 12th 2006, 02:06:33 pmMaybe the file is larger than MAX_ALLOWED_PACKET?
See here for an example how to upload a file into DB: http://php.net/manual/en/function.mysqli-stmt-send-long-data.php
Reply
Lars Strojny says:
published on May 12th 2006, 04:53:13 pmGuess that
Reply