xref: /PHP-8.3/ext/pdo_oci/tests/bug46274_2.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, false);
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($row = $res->fetch());
53var_dump(fread($row[0], 1024));
54fclose($row[0]);
55
56// Empty string
57var_dump($row = $res->fetch());
58var_dump(fread($row[0], 1024));
59fclose($row[0]);
60
61$db->exec("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) ""
79