xref: /PHP-8.3/ext/pdo/tests/bug_34630.phpt (revision 74859783)
1--TEST--
2PDO Common: Bug #34630 (inserting streams as LOBs)
3--EXTENSIONS--
4pdo
5--SKIPIF--
6<?php
7$dir = getenv('REDIR_TEST_DIR');
8if (false == $dir) die('skip no driver');
9require_once $dir . 'pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
15require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17
18$driver = $db->getAttribute(PDO::ATTR_DRIVER_NAME);
19$is_oci = $driver == 'oci';
20
21if ($is_oci) {
22    $db->exec('CREATE TABLE test (id int NOT NULL PRIMARY KEY, val BLOB)');
23} else {
24    $db->exec('CREATE TABLE test (id int NOT NULL PRIMARY KEY, val VARCHAR(256))');
25}
26$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
27
28$fp = tmpfile();
29fwrite($fp, "I am the LOB data");
30rewind($fp);
31
32if ($is_oci) {
33    /* oracle is a bit different; you need to initiate a transaction otherwise
34     * the empty blob will be committed implicitly when the statement is
35     * executed */
36    $db->beginTransaction();
37    $insert = $db->prepare("insert into test (id, val) values (1, EMPTY_BLOB()) RETURNING val INTO :blob");
38} else {
39    $insert = $db->prepare("insert into test (id, val) values (1, :blob)");
40}
41$insert->bindValue(':blob', $fp, PDO::PARAM_LOB);
42$insert->execute();
43$insert = null;
44
45$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
46var_dump($db->query("SELECT * from test")->fetchAll(PDO::FETCH_ASSOC));
47
48?>
49--EXPECT--
50array(1) {
51  [0]=>
52  array(2) {
53    ["id"]=>
54    string(1) "1"
55    ["val"]=>
56    string(17) "I am the LOB data"
57  }
58}
59