xref: /PHP-5.6/ext/pdo/pdo.php (revision 5a2cb415)
1<?php
2dl('pdo.so');
3dl('pdo_sqlite.so');
4
5//$x = new PDO("oci:dbname=hostname", 'php', 'php');
6$x = new PDO("sqlite::memory:");
7
8$x->query("create table test(name string, value string)");
9debug_zval_dump($x);
10
11$stmt = $x->prepare("INSERT INTO test (NAME, VALUE) VALUES (:name, :value)");
12
13$stmt->bindParam(":name", $the_name, PDO_PARAM_STR, 32);
14$stmt->bindParam(":value", $the_value, PDO_PARAM_STR, 32);
15
16for ($i = 0; $i < 4; $i++) {
17	$the_name = "foo" . rand();
18	$the_value = "bar" . rand();
19
20	if (!$stmt->execute()) {
21		break;
22	}
23}
24
25$stmt = null;
26
27echo "DEFAULT:\n";
28foreach ($x->query("select NAME, VALUE from test") as $row) {
29	print_r($row);
30}
31
32echo "OBJ:\n";
33
34class Foo {
35	public $NAME = "Don't change me";
36}
37
38$foo = new foo;
39
40foreach ($x->query("select NAME, VALUE from test", PDO_FETCH_COLUMN, 1) as $row) {
41	debug_zval_dump($row);
42}
43
44echo "Done\n";
45exit;
46
47$stmt = $x->prepare("select NAME, VALUE from test where value like ?");
48$the_name = 'bar%';
49$stmt->execute(array($the_name)) or die("failed to execute!");
50$stmt->bindColumn('VALUE', $value);
51
52while ($row = $stmt->fetch()) {
53	echo "name=$row[NAME] value=$row[VALUE]\n";
54	echo "value is $value\n";
55	echo "\n";
56}
57
58echo "Let's try an update\n";
59
60echo "All done\n";
61
62?>
63