Topic
  • 2 replies
  • Latest Post - ‏2009-10-05T18:33:54Z by SystemAdmin
SystemAdmin
SystemAdmin
5837 Posts

Pinned topic store pdf file in blob fails if the file size is bigger than 16Kbyte

‏2009-09-27T09:58:10Z |
I use PHP 5.2.9-2, Apache 2.2.11, DB2 8.2 administration client in local server and DB2 Express 9 installed in a remote server.

I can insert a pdf file into a blob field. But it fails if the file is too big (around 16Kbyte). The blob size in db2 is 1Mbyte.

I use the php_ibm_db2.dll driver. I also try to use the odbc driver. Both have the same problem. I hope someone help to find out what is wrong. The error message I get is "Statement Execute Failed"

Below is my php source using php_ibm_db2.dll driver.

$name = "c:/10.pdf";
$dataString = file_get_contents($name);
$data = bin2hex($dataString);
$dblink = db2_pconnect ("sample", "administrator", "password");
$sql = "insert into pdffile (id, filecon) VALUES ('10.pdf', blob(X'$data'))";
$result = db2_exec($dblink, $sql);
if($result) {
echo "OK";
} else {
echo "NG";
}
Updated on 2009-10-05T18:33:54Z at 2009-10-05T18:33:54Z by SystemAdmin
  • LeoPetraz
    LeoPetraz
    228 Posts

    Re: store pdf file in blob fails if the file size is bigger than 16Kbyte

    ‏2009-10-02T19:32:07Z  
    Hi doctorhung,

    You need to use a prepared statement to insert anything bigger than 32k.

    $array = array('10.pdf', $data);
    $sql = "insert into pdffile (id, filecon) VALUES (?, blob(?))";
    $stmt = db2_prepare($dblink, $sql);
    $success = db2_execute($stmt, $array);


    db2_prepare()

    Note that $success is boolean, not a resource. If you are running a query, the rows are fetched from the $stmt resource.

    Regards,

    Leons Petrazickis
    db2x (at) ca.ibm.com
    DB2 Express-C Community Team
  • SystemAdmin
    SystemAdmin
    5837 Posts

    Re: store pdf file in blob fails if the file size is bigger than 16Kbyte

    ‏2009-10-05T18:33:54Z  
    • LeoPetraz
    • ‏2009-10-02T19:32:07Z
    Hi doctorhung,

    You need to use a prepared statement to insert anything bigger than 32k.

    $array = array('10.pdf', $data);
    $sql = "insert into pdffile (id, filecon) VALUES (?, blob(?))";
    $stmt = db2_prepare($dblink, $sql);
    $success = db2_execute($stmt, $array);


    db2_prepare()

    Note that $success is boolean, not a resource. If you are running a query, the rows are fetched from the $stmt resource.

    Regards,

    Leons Petrazickis
    db2x (at) ca.ibm.com
    DB2 Express-C Community Team
    Dear Leons,

    Do we need to turn off the autocommit and issue the db2_commit separately ? Some blogs suggest me to do that for blog operation.

    Regards,
    Doctor Hung