xref: /PHP-5.3/ext/pdo_pgsql/tests/bug46274_2.phpt (revision 0b576f6f)
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_pgsql')) die('skip not loaded');
6require dirname(__FILE__) . '/config.inc';
7require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8PDOTest::skip();
9?>
10--FILE--
11<?php
12require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
13$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
14
15$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
16
17$db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)');
18
19$stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)");
20
21$data = 'foo';
22$blob = fopen('php://memory', 'a');
23fwrite($blob, $data);
24rewind($blob);
25
26$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
27$stmt->execute();
28
29$blob = '';
30$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
31$stmt->execute();
32
33$data = '';
34$blob = fopen('php://memory', 'a');
35fwrite($blob, $data);
36rewind($blob);
37
38$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
39$stmt->execute();
40
41$blob = NULL;
42$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
43$stmt->execute();
44
45$res = $db->query("SELECT blob1 from test_one_blob");
46// Resource
47var_dump($x = $res->fetch());
48var_dump(fread($x['blob1'], 10));
49
50// Resource
51var_dump($res->fetch());
52var_dump(fread($x['blob1'], 10));
53
54// Resource
55var_dump($res->fetch());
56var_dump(fread($x['blob1'], 10));
57
58// NULL
59var_dump($res->fetch());
60
61$db->query('DROP TABLE test_one_blob');
62
63?>
64--EXPECTF--
65array(2) {
66  ["blob1"]=>
67  resource(%d) of type (stream)
68  [0]=>
69  resource(%d) of type (stream)
70}
71string(3) "foo"
72array(2) {
73  ["blob1"]=>
74  resource(%d) of type (stream)
75  [0]=>
76  resource(%d) of type (stream)
77}
78string(0) ""
79array(2) {
80  ["blob1"]=>
81  resource(%d) of type (stream)
82  [0]=>
83  resource(%d) of type (stream)
84}
85string(0) ""
86array(2) {
87  ["blob1"]=>
88  NULL
89  [0]=>
90  NULL
91}
92