xref: /PHP-8.2/ext/pdo_oci/tests/bug46274.phpt (revision 39131219)
1--TEST--
2Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and blob)
3--EXTENSIONS--
4pdo
5pdo_oci
6--SKIPIF--
7<?php
8require __DIR__.'/../../pdo/tests/pdo_test.inc';
9PDOTest::skip();
10?>
11--FILE--
12<?php
13require 'ext/pdo/tests/pdo_test.inc';
14$db = PDOTest::test_factory('ext/pdo_oci/tests/common.phpt');
15$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
16
17$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
18
19try {
20    $db->exec("DROP TABLE test_one_blob");
21} catch (Exception $e) {
22}
23
24$db->beginTransaction();
25
26$db->query('CREATE TABLE test_one_blob (id INT NOT NULL, blob1 BLOB)');
27
28$stmt = $db->prepare("INSERT INTO test_one_blob (id, blob1) VALUES (:id, EMPTY_BLOB()) RETURNING blob1 INTO :foo");
29
30$data = 'foo';
31$blob = fopen('php://memory', 'a');
32fwrite($blob, $data);
33rewind($blob);
34
35$id = 1;
36$stmt->bindparam(':id', $id);
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$id = 1;
46$stmt->bindparam(':id', $id);
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($res->fetch());
53
54// Empty string
55var_dump($res->fetch());
56
57$db->exec("DROP TABLE test_one_blob");
58
59?>
60--EXPECT--
61array(2) {
62  ["blob1"]=>
63  string(3) "foo"
64  [0]=>
65  string(3) "foo"
66}
67array(2) {
68  ["blob1"]=>
69  string(0) ""
70  [0]=>
71  string(0) ""
72}
73