xref: /PHP-5.5/ext/oci8/tests/define2.phpt (revision c7a8bd6a)
1--TEST--
2Test oci_define_by_name types
3--SKIPIF--
4<?php
5$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
6require(dirname(__FILE__).'/skipif.inc');
7?>
8--FILE--
9<?php
10
11require(dirname(__FILE__)."/connect.inc");
12
13$stmtarray = array(
14	"drop table phptestrawtable",
15	"create table phptestrawtable( id number(10), fileimage raw(1000))"
16);
17
18oci8_test_sql_execute($c, $stmtarray);
19
20$stmt = oci_parse ($c, "insert into phptestrawtable (id, fileimage) values (:id, :fileimage)");
21$i=1;
22$fileimage = file_get_contents( dirname(__FILE__)."/test.gif");
23$fileimage = substr($fileimage, 0, 300);
24var_dump(md5($fileimage));
25
26oci_bind_by_name( $stmt, ":id", $i, -1);
27oci_bind_by_name( $stmt, ":fileimage", $fileimage, -1, SQLT_BIN);
28oci_execute($stmt, OCI_DEFAULT);
29oci_commit($c);
30
31echo "Test 1\n";
32$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
33var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi));
34oci_execute($stmt);
35
36while (oci_fetch($stmt)) {
37	var_dump($fi);
38	echo "file md5:" . md5($fi) . "\n";
39}
40
41echo "Test 2\n";
42$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
43var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi));
44oci_execute($stmt);
45
46while (oci_fetch($stmt)) {
47	var_dump($fi);
48	echo "file md5:" . md5($fi) . "\n";
49}
50
51echo "Test 3 - test repeatability\n";
52$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
53var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi, SQLT_STR));
54oci_execute($stmt);
55
56while (oci_fetch($stmt)) {
57	var_dump($fi);
58	echo "file md5:" . md5($fi) . "\n";
59}
60
61echo "Test 4 - wrong type\n";
62$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
63var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi, SQLT_RSET));
64oci_execute($stmt);
65
66while (oci_fetch($stmt)) {
67	var_dump($fi);
68	echo "file md5:" . md5($fi) . "\n";
69}
70
71// Cleanup
72
73$stmtarray = array(
74    "drop table phptestrawtable"
75);
76
77oci8_test_sql_execute($c, $stmtarray);
78
79echo "Done\n";
80?>
81--EXPECTF--
82string(32) "88b274d7a257ac6f70435b83abd4e26e"
83Test 1
84bool(true)
85string(300) "GIF89%s"
86file md5:88b274d7a257ac6f70435b83abd4e26e
87Test 2
88bool(true)
89string(300) "GIF89%s"
90file md5:88b274d7a257ac6f70435b83abd4e26e
91Test 3 - test repeatability
92bool(true)
93string(600) "47494638396178004300E66A007F82B839374728252ACCCDE2A1A4CBD3D5E7B2B4D44342588386B98283B35252729092C2C2C4DEAAACD04C4B635B5C83DDDEEC3B383C6E71A56A6D9D61638D7579B17B7EB5E5E6F0999CC68C8DC1B9BAD96B6B924E4E6B7174A97A7AA3888BBD7274A37473988E90C15A5B7EE2E3EF7B7DADA4A5D06D70A27276AC9596C8BBBDD97478AE8588BB9295C3D8D9EA9292C46466926B6E9FA5A8CE9496C52E2B2F535168B3B4D76C6A8C5C5B768A8DBF666896686A9A9C9FC8312E39AEB0D39C9CCD5556789EA1CA9699C58182AF6769973F3D50BCBEDA5E60899899C88C8EBF898ABA57587CB6B7D7D5D7E8221E206C6F9ECED0E4BFC0DC777BB47678A75F5E7D9999CC6E6F987377AE221E1FFFFFFF908E8F595657C7C6C7EEEEF5D5D4D5F6F6"
94file md5:80bb3201e2a8bdcb8ab3e1a44a82bb8a
95Test 4 - wrong type
96bool(true)
97
98Warning: oci_fetch(): ORA-00932: inconsistent datatypes%s on line %d
99Done
100