Bug #77067 [Com]: Inserting a BLOB from a stream transforms it to a string

From: Date: Wed, 05 Dec 2018 10:57:46 +0000
Subject: Bug #77067 [Com]: Inserting a BLOB from a stream transforms it to a string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218276@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77067&edit=1

 ID:                 77067
 Comment by:         sjon at hortensius dot net
 Reported by:        php at bohwaz dot net
 Summary:            Inserting a BLOB from a stream transforms it to a
                     string
 Status:             Open
 Type:               Bug
 Package:            PDO SQLite
 Operating System:   All
 PHP Version:        7.3.0RC4
 Block user comment: N
 Private report:     N

 New Comment:

FWIW this isn't necessarily 7.3 specific - it has been like this ever since php 7.0, see https://3v4l.org/tg2Gl


Previous Comments:
------------------------------------------------------------------------
[2018-10-26 14:14:35] php at bohwaz dot net

Description:
------------
If passing a stream as a parameter of PDOStatement::bindParam it is transformed to a string which
contains the stream contents.

For example this prevents reusing the stream handle to close it properly or to truncate or change
the file contents.

Test script:
---------------
<?php

$pdo = new PDO('sqlite::memory:');
$pdo->exec('CREATE TABLE test (a INTEGER, b BLOB);');

$fp = tmpfile();
fwrite($fp, 'Random stuff!');
fseek($fp, 0);

$stmt = $pdo->prepare('INSERT INTO test VALUES (?, ?);');
$stmt->bindValue(1, 42);
$stmt->bindParam(2, $fp, PDO::PARAM_LOB);

$stmt->execute();

var_dump(gettype($fp));

Expected result:
----------------
resource

Actual result:
--------------
string


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77067&edit=1


Thread (3 messages)

« previous php.bugs (#218276) next »