1--TEST-- 2Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and blob) 3--EXTENSIONS-- 4pdo 5pdo_pgsql 6--SKIPIF-- 7<?php 8require __DIR__ . '/config.inc'; 9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 10PDOTest::skip(); 11?> 12--FILE-- 13<?php 14require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 15$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); 16 17$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 18 19try { 20 @$db->query("SET bytea_output = 'escape'"); 21} catch (Exception $e) { 22} 23 24$db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)'); 25 26$stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)"); 27 28$data = 'foo'; 29$blob = fopen('php://memory', 'a'); 30fwrite($blob, $data); 31rewind($blob); 32 33$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); 34$stmt->execute(); 35 36$blob = ''; 37$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); 38$stmt->execute(); 39 40$data = ''; 41$blob = fopen('php://memory', 'a'); 42fwrite($blob, $data); 43rewind($blob); 44 45$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); 46$stmt->execute(); 47 48$blob = NULL; 49$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB); 50$stmt->execute(); 51 52$res = $db->query("SELECT blob1 from test_one_blob"); 53// Resource 54var_dump($res->fetch()); 55 56// Empty string 57var_dump($res->fetch()); 58 59// Empty string 60var_dump($res->fetch()); 61 62// NULL 63var_dump($res->fetch()); 64 65$db->query('DROP TABLE test_one_blob'); 66 67?> 68--EXPECT-- 69array(2) { 70 ["blob1"]=> 71 string(3) "foo" 72 [0]=> 73 string(3) "foo" 74} 75array(2) { 76 ["blob1"]=> 77 string(0) "" 78 [0]=> 79 string(0) "" 80} 81array(2) { 82 ["blob1"]=> 83 string(0) "" 84 [0]=> 85 string(0) "" 86} 87array(2) { 88 ["blob1"]=> 89 NULL 90 [0]=> 91 NULL 92} 93