php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41831 pdo_sqlite changes resource to text
Submitted: 2007-06-27 21:18 UTC Modified: 2007-08-01 22:45 UTC
From: bennovandenberg at gmail dot com Assigned: iliaa
Status: Closed Package: PDO related
PHP Version: 5.2.3 OS: FreeBSD 6.2
Private report: No CVE-ID:
 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-27 21:27 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2007-06-28 12:57 UTC] bennovandenberg at gmail dot com
I've created a complete script to demonstrate the bug. It's too big to upload here, so I've uploaded it to my own webserver. The only things that need to be changed are the database in use, the settings for the database and a location of a image (any file will do actually). Also if a other database then mysql or sqlite are used, then $auto needs to be updated to include the auto increment keyword (mysql and sqlite use different ones).

The url: http://develop.hatchan.nl/misc/bugs/php/pdo_sqlite/resource.phps

With sqlite
Outcome expected is:
It's a resource!
It's a resource!

Actual result:
It's a resource!
It's not a resource
 [2007-06-29 12:09 UTC] tony2001@php.net
The server is not available. Please try to make a SHORT but COMPLETE reproduce case, so that there would be no need to put it somewhere.
 [2007-06-29 15:17 UTC] bennovandenberg at gmail dot com
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 />";
?>
 [2007-08-01 22:45 UTC] iliaa@php.net
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.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 12:02:07 2014 UTC