1--TEST-- 2Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and blob) 3--SKIPIF-- 4<?php 5if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) 6die('skip not loaded'); 7require dirname(__FILE__).'/../../pdo/tests/pdo_test.inc'; 8PDOTest::skip(); 9?> 10--FILE-- 11<?php 12require 'ext/pdo/tests/pdo_test.inc'; 13$db = PDOTest::test_factory('ext/pdo_oci/tests/common.phpt'); 14$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 15 16$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); 17 18try { 19 $db->exec("DROP TABLE test_one_blob"); 20} catch (Exception $e) { 21} 22 23$db->beginTransaction(); 24 25$db->query('CREATE TABLE test_one_blob (id INT NOT NULL, blob1 BLOB)'); 26 27$stmt = $db->prepare("INSERT INTO test_one_blob (id, blob1) VALUES (:id, EMPTY_BLOB()) RETURNING blob1 INTO :foo"); 28 29$data = 'foo'; 30$blob = fopen('php://memory', 'a'); 31fwrite($blob, $data); 32rewind($blob); 33 34$id = 1; 35$stmt->bindparam(':id', $id); 36$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); 37$stmt->execute(); 38 39$data = ''; 40$blob = fopen('php://memory', 'a'); 41fwrite($blob, $data); 42rewind($blob); 43 44$id = 1; 45$stmt->bindparam(':id', $id); 46$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); 47$stmt->execute(); 48 49$res = $db->query("SELECT blob1 from test_one_blob"); 50// Resource 51var_dump($row = $res->fetch()); 52var_dump(fread($row[0], 1024)); 53fclose($row[0]); 54 55// Empty string 56var_dump($row = $res->fetch()); 57var_dump(fread($row[0], 1024)); 58fclose($row[0]); 59 60$db->exec("DROP TABLE test_one_blob"); 61 62?> 63--EXPECTF-- 64array(2) { 65 ["blob1"]=> 66 resource(%d) of type (stream) 67 [0]=> 68 resource(%d) of type (stream) 69} 70string(3) "foo" 71array(2) { 72 ["blob1"]=> 73 resource(%d) of type (stream) 74 [0]=> 75 resource(%d) of type (stream) 76} 77string(0) "" 78