xref: /PHP-7.4/ext/pdo_oci/tests/bug46274.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_oci'))
6die('skip not loaded');
7require __DIR__.'/../../pdo/tests/pdo_test.inc';
8PDOTest::skip();
9?>
10--FILE--
11<?php
12require 'ext/pdo/tests/pdo_test.inc';
13$db = PDOTest::test_factory('ext/pdo_oci/tests/common.phpt');
14$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15
16$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
17
18try {
19	$db->exec("DROP TABLE test_one_blob");
20} catch (Exception $e) {
21}
22
23$db->beginTransaction();
24
25$db->query('CREATE TABLE test_one_blob (id INT NOT NULL, blob1 BLOB)');
26
27$stmt = $db->prepare("INSERT INTO test_one_blob (id, blob1) VALUES (:id, EMPTY_BLOB()) RETURNING blob1 INTO :foo");
28
29$data = 'foo';
30$blob = fopen('php://memory', 'a');
31fwrite($blob, $data);
32rewind($blob);
33
34$id = 1;
35$stmt->bindparam(':id', $id);
36$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
37$stmt->execute();
38
39$data = '';
40$blob = fopen('php://memory', 'a');
41fwrite($blob, $data);
42rewind($blob);
43
44$id = 1;
45$stmt->bindparam(':id', $id);
46$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
47$stmt->execute();
48
49$res = $db->query("SELECT blob1 from test_one_blob");
50// Resource
51var_dump($res->fetch());
52
53// Empty string
54var_dump($res->fetch());
55
56$db->exec("DROP TABLE test_one_blob");
57
58?>
59--EXPECT--
60array(2) {
61  ["blob1"]=>
62  string(3) "foo"
63  [0]=>
64  string(3) "foo"
65}
66array(2) {
67  ["blob1"]=>
68  string(0) ""
69  [0]=>
70  string(0) ""
71}
72