xref: /PHP-8.3/ext/pdo_pgsql/tests/bug46274_2.phpt (revision 4f84b159)
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, false);
18
19try {
20        @$db->query("SET bytea_output = 'escape'");
21} catch (Exception $e) {
22}
23
24$db->query('CREATE TABLE test_one_blob_46274_2 (id SERIAL NOT NULL, blob1 BYTEA)');
25
26$stmt = $db->prepare("INSERT INTO test_one_blob_46274_2 (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_46274_2");
53// Resource
54var_dump($x = $res->fetch());
55var_dump(fread($x['blob1'], 10));
56
57// Resource
58var_dump($res->fetch());
59var_dump(fread($x['blob1'], 10));
60
61// Resource
62var_dump($res->fetch());
63var_dump(fread($x['blob1'], 10));
64
65// NULL
66var_dump($res->fetch());
67?>
68--CLEAN--
69<?php
70require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
71$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
72$db->query('DROP TABLE IF EXISTS test_one_blob_46274_2');
73?>
74--EXPECTF--
75array(2) {
76  ["blob1"]=>
77  resource(%d) of type (stream)
78  [0]=>
79  resource(%d) of type (stream)
80}
81string(3) "foo"
82array(2) {
83  ["blob1"]=>
84  resource(%d) of type (stream)
85  [0]=>
86  resource(%d) of type (stream)
87}
88string(0) ""
89array(2) {
90  ["blob1"]=>
91  resource(%d) of type (stream)
92  [0]=>
93  resource(%d) of type (stream)
94}
95string(0) ""
96array(2) {
97  ["blob1"]=>
98  NULL
99  [0]=>
100  NULL
101}
102