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