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