PDO SQLite driving me mad!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I really don't know what is going on here. Can anyone shed some light on this please?

I'm trying to store an image in a SQLite database using PDO. The code given on http://uk2.php.net/manual/en/ref.pdo.php under Example 1669 is basically wrong - you can't beginTransaction() on a statement for example! So I had to rewrite it a little, but no matter what, it just doesn't work.

The problem appears to be the PDO LOB type. It will only ever send the first 21 bytes of the image to the database no matter what I try. Here's some code:

$stmt = $db->prepare('INSERT INTO Test (name, data) VALUES (?,?)');
$stmt->bindParam(1, $name, PDO::PARAM_STR, 60);
$stmt->bindParam(2, $pic_data, PDO::PARAM_LOB);
$stmt->execute();

The database is alive and well, and can be written to just fine, as is proven by the fact that I do get SOME data in there, just not all of it! I have tried a variety of files to no end.

According to the PHP docs PDO LOB should work on streams as well, so I tried adding:

$fp = fopen($filename, 'rb');

To my script, and then changing the LOB line to:

$stmt->bindParam(2, $fp, PDO::PARAM_LOB);

Thinking it would work out what to do with the newly found stream. But no, yet again all I get are the first 21 bytes.

Using SQLite Maestro I can view the inserted data, and it's always too short. If I use the SQLite Maestro interface to insert an image, it works fine. PDO SQLite seems to always fail when trying to extract a LOB for display though, but that's another issue.

PHP 5.2.1 - ideas, anyone?!

Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux