2

Is there anything special I need to do when selecting a blob from MySQL? I get a NULL for the following (data is a mediumblob, file_extension is varchar):

$sql = "SELECT data, file_extension FROM table1 WHERE table1.id = ?";
$q = $con->prepare($sql);
$q->execute(array(1));

if ($q->rowCount() == 0)
{
    disconnectSqlConnection($con);
    $arr = array('success' => 'false',
                 'error'   => -2);
    return json_encode($arr);
}
else
{
    $row = $q->fetch();
    $arr = array('success'   => 'true',
                 'data'      => $row[0],
                 'extension' => $row[1]);
    disconnectSqlConnection($con);
    return json_encode($arr);
}

$row[1] has 'pdf', which is correct. $row[0] is NULL, but in the database, I see a blob of size 244.8KB

Any thoughts?

1 Answer 1

2

use CAST to convert it to text

$sql = "SELECT CAST(data AS CHAR(10000) CHARACTER SET utf8) as data, file_extension FROM table1 WHERE table1.id = ?";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.