|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-06-27 21:18 UTC] bennovandenberg at gmail dot com
Description:
------------
pdo_sqlite replaces a resource variable with the content of the file as text. This happens after the execute command. I tried the same with mysql, but with pdo_mysql it still stays a resource. So I guess the problem is with pdo_sqlite. (or its normal behavior to change the resource to text, but then pdo_mysql is wrong)
Reproduce code:
---------------
$pdo = new PDO("sqlite:/somepath/mydb.sq3");
$filename = "test";
$imagehandle = fopen($imagelocation, 'r');
// is_resource($imagehandle) == true
$stmt = $pdo->prepare("INSERT INTO Images (filename, image_data) VALUES (?,?);");
$stmt->bindParam(1, $filename);
$stmt->bindParam(2, $imagehandle, PDO::PARAM_LOB);
$stmt->execute();
// is_resource($imagehandle) == false
Expected result:
----------------
After the execute() I espect the $imagehandle to still be a resource.
Actual result:
--------------
$imagehandle has become a string with the content of the image.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 20:00:01 2025 UTC |
The site works fine here, but here it is a slightly SHORTER and COMPLETE version... <?php $pdo = new PDO("sqlite:/somedatabase.sq3"); $imagelocation = "/someimage"; // or any other file $pdo->exec("CREATE TABLE Images (id INTEGER PRIMARY KEY AUTOINCREMENT, filename VARCHAR(50), image_data LONGBLOB)" ); $filename = "test"; $imagehandle = fopen($imagelocation, 'r'); if (is_resource($imagehandle)) echo "It's a resource!<br />"; else echo "It's not a resource<br />"; $stmt = $pdo->prepare("INSERT INTO Images (filename, image_data) VALUES (?,?);"); $stmt->bindParam(1, $filename); $stmt->bindParam(2, $imagehandle, PDO::PARAM_LOB); $stmt->execute(); if (is_resource($imagehandle)) echo "It's a resource!<br />"; else echo "It's not a resource<br />"; ?>