ID: 41135 Updated by: [EMAIL PROTECTED] Reported By: rich at corephp dot co dot uk -Status: Assigned +Status: Closed Bug Type: PDO related Operating System: Windows XP SP2 PHP Version: 5.2.1 Assigned To: scottmac New Comment:
This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. In 5.3+ at the moment. Previous Comments: ------------------------------------------------------------------------ [2008-02-07 09:44:11] [EMAIL PROTECTED] There is a patch attached to another bug which deals with this. http://bugs.php.net/bug.php?id=42443 ------------------------------------------------------------------------ [2008-02-06 20:58:50] nospam dot list at unclassified dot de So, here we are. I can confirm that PDO SQLite truncates BLOB data at the first \x00 character. It's not binary-safe. I tried to write a JPEG file and it's only 4 bytes long. Looking at the file in a hex viewer, the byte no. 5 is a NUL. PHP version: 5.2.3 (from xampp) on Windows XP Not quite up-to-date, but this bug isn't marked as fixed so the issue is the same. It really does exist, for those in doubt. This is a rather old bug and it's still in discussion. Is there any progress already? Will it be fixed or is it considered "irrelevant"? (I'm asking this because I see so many severe bugs being forgotten in many public bug trackers.) ------------------------------------------------------------------------ [2008-02-03 22:40:55] chx1975 at gmail dot com My final note here is that you can avoid a temporary file with the php://memory stream. $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); $stmt->bindParam(':len', $len); $blob = fopen('php://memory', 'a'); $len = fwrite($blob, $binarydata); rewind($blob); ------------------------------------------------------------------------ [2008-02-03 22:33:33] chx1975 at gmail dot com Based on http://netevil.org/blog/2005/oct/lob-support-added-to-pdo-oci-in-php-5-1-cvs-finally I believe maciej dot pijanka at gmail dot com wants this code: $db = new PDO(...); $binarydata = "abcdefg\x00a\x00\x01\x02"; $db->exec('CREATE TABLE test (data bytea, comment varchar(64), len integer)'); $db->beginTransaction(); $a = tempnam('.', 'pdo'); file_put_contents($a, $binarydata); $stmt = $db->prepare("INSERT INTO test (data, comment, len) VALUES (:data, :comment, :len)"); $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); $comment = 'lob'; $stmt->bindParam(':comment', $comment); $len = filesize($a); $stmt->bindParam(':len', $len); $blob = fopen($a, 'rb'); $stmt->execute(); $db->commit(); unlink($a); print "\nFetching and comparing data\n"; # with fetchall resources don't work too $stmt = $db->prepare("select * from test"); $stmt->execute(); $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES,true); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $buffer = ''; var_dump($row); if(is_resource($row['data'])) { $buffer = stream_get_contents($row['data']); } else $buffer = $row['data']; print "Test `".$row['comment']."' StrCmp:"; print "".(strcmp($binarydata,$buffer) == 0 )?"equal":"fail"; print " length stored in db: ". $row['len'] . ", returned data len: ".strlen($buffer)."\n"; echo bin2hex($buffer)."\n"; } $db->exec('DROP TABLE test'); ------------------------------------------------------------------------ [2008-02-03 20:43:34] chx1975 at gmail dot com I just ran Wez's test code and got 006100 so it seems I am unable to reproduce this bug. PECL Module version => 1.0.1 $Id: pdo_sqlite.c,v 1.10.2.6.2.2 2007/03/23 14:30:00 wez Exp $ SQLite library => 3.4.2 ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/41135 -- Edit this bug report at http://bugs.php.net/?id=41135&edit=1