Back to index

php5  5.3.10
pdo.php
Go to the documentation of this file.
00001 <?php
00002 dl('pdo.so');
00003 dl('pdo_sqlite.so');
00004 
00005 //$x = new PDO("oci:dbname=hostname", 'php', 'php');
00006 $x = new PDO("sqlite::memory:");
00007 
00008 $x->query("create table test(name string, value string)");
00009 debug_zval_dump($x);
00010 
00011 $stmt = $x->prepare("INSERT INTO test (NAME, VALUE) VALUES (:name, :value)");
00012 
00013 $stmt->bindParam(":name", $the_name, PDO_PARAM_STR, 32);
00014 $stmt->bindParam(":value", $the_value, PDO_PARAM_STR, 32);
00015 
00016 for ($i = 0; $i < 4; $i++) {
00017        $the_name = "foo" . rand();
00018        $the_value = "bar" . rand();
00019 
00020        if (!$stmt->execute()) {
00021               break;
00022        }
00023 }
00024 
00025 $stmt = null;
00026 
00027 echo "DEFAULT:\n";
00028 foreach ($x->query("select NAME, VALUE from test") as $row) {
00029        print_r($row);
00030 }
00031 
00032 echo "OBJ:\n";
00033 
00034 class Foo {
00035        public $NAME = "Don't change me";
00036 }
00037 
00038 $foo = new foo;
00039 
00040 foreach ($x->query("select NAME, VALUE from test", PDO_FETCH_COLUMN, 1) as $row) {
00041        debug_zval_dump($row);
00042 }
00043 
00044 echo "Done\n";
00045 exit;
00046 
00047 $stmt = $x->prepare("select NAME, VALUE from test where value like ?");
00048 $the_name = 'bar%';
00049 $stmt->execute(array($the_name)) or die("failed to execute!");
00050 $stmt->bindColumn('VALUE', $value);
00051 
00052 while ($row = $stmt->fetch()) {
00053        echo "name=$row[NAME] value=$row[VALUE]\n";
00054        echo "value is $value\n";
00055        echo "\n";
00056 }
00057 
00058 echo "Let's try an update\n";
00059 
00060 echo "All done\n";
00061 
00062 ?>