pdo.php 1.2 KB

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