MySQL Forums
Forum List  »  Connector/ODBC

Re: incorrect string value
Posted by: Peter Brawley
Date: January 19, 2021 03:56PM

> I need to select data as hex?

In order to diagnose what's wrong---the idea is to see exactly what you've stored in the table, specifically whether the question marks you saw were due to your UI failing to interpret what it was given, or whether the stored data is in fact a string of question marks.

Clearly it's the latter. You've been inserting corrupt blobs.

So you need to check every step, from your data source through to your table, to see when and how the corruption occurs---at each stage testing the method and tool you used against the result of a method that's you've proved to be correct & reliable.

Here's a little php script that will reliably save a blob to a table, and test the saved result against the source. You need to execute something like this, in the language of your choice, for each of your blob-processing steps ...

<?php
$mysqli = new mysqli( 'localhost', '...', '...', 'test' );
$mysqli->query( "drop table if exists blob_tb" );
$mysqli->query( "create table if not exists blob_tb( bdata blob)" );
$imgfile = "SPECIFY_IMG_FILE";

$sql = "INSERT INTO blob_tb (bdata) VALUES(?)";
$insertStm = $mysqli->prepare($sql);

$blob = NULL; //necessary
$insertStm->bind_param('b', $blob);

$blob = (binary) ( file_get_contents($imgfile) );
$insertStm->send_long_data(0, $blob);
$insertStm->execute();
$insertStm->close();

$selectStm = $mysqli->prepare("SELECT bdata FROM blob_tb LIMIT 1");
$selectStm->execute();

$selectStm->bind_result($savedBlob);
$selectStm->fetch();
$selectStm->close();

$mysqli->close();

echo 'src and save result are equal: ' . ((int) ($blob == $savedBlob));

?>

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.