Source for file test_queryresult.php

Documentation is available at test_queryresult.php

  1. <?php
  2. /**
  3.  * Tests QueryResult() functions.
  4.  * This script is used during development of the class itself.
  5.  * @author Sascha 'SieGeL' Pfalz <php@saschapfalz.de>
  6.  * @package db_SQLite
  7.  * @subpackage Examples
  8.  * @version 0.20 (07-Aug-2010)
  9.  *  $Id: test_queryresult.php,v 1.1 2010/08/07 17:47:05 siegel Exp $
  10.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  11.  * @filesource
  12.  */
  13. /**
  14.  * Load in the general functions for all tests.
  15.  */
  16. require_once('functions.inc.php');
  17.  
  18. /** Define the name of the database to use for this example: */
  19. define('SQLITEDB_TESTDB'  '/tmp/test.dbf');
  20.  
  21. // Determine SAPI type
  22. $d WhichBR();
  23.  
  24. // Create new instance of class
  25. $db new db_SQLite();
  26.  
  27. // Before doing anything connect first!
  28. $db->Connect(SQLITEDB_TESTDB);
  29.  
  30. if($d['SAPI'!= 'cli')
  31.   {
  32.   echo('<pre>');
  33.   }
  34.  
  35. echo($d['LF'].'QueryResult() Test for SQLite class'.$d['LF'].$d['LF']);
  36.  
  37. $test_table = <<<SQL
  38. CREATE TABLE DB_SQLITE_T1
  39.   (
  40.   ID      INTEGER PRIMARY KEY,
  41.   VALUE   VARCHAR(100)
  42.   )
  43. SQL;
  44.  
  45. CheckForDBobject($db,"DB_SQLITE_T1",$test_table);
  46.  
  47. // Fetch the list of existing objects inside our database:
  48. $query=<<<EOM
  49. SELECT name FROM
  50.    (
  51.     SELECT * FROM sqlite_master
  52.     UNION ALL
  53.     SELECT * FROM sqlite_temp_master
  54.    )
  55. WHERE type='table'
  56. ORDER BY name
  57. EOM;
  58. $stmt $db->QueryResult($query);
  59. $rows $db->NumRows($stmt);
  60. printf("%d table(s) found in database %s%s%s",$rows,SQLITEDB_TESTDB,$d['LF'],$d['LF']);
  61. $lv 1;
  62. while($t $db->FetchResult($stmt))
  63.   {
  64.   printf("Tablename.%d=%s %s",$lv,$t['name'],$d['LF']);
  65.   $lv++;
  66.   }
  67. $db->FreeResult($stmt);
  68.  
  69. printf("%sNow adding 10 rows of random data and reading them: %s%s",$d['LF'],$d['LF'],$d['LF']);
  70. for($i 0$i 10$i++)
  71.   {
  72.   $random mt_rand(0,99999);
  73.   $db->Query("INSERT INTO DB_SQLITE_T1(VALUE) VALUES(".$random.")");
  74.   }
  75. printf("Ok, 10 rows added.%s%s",$d['LF'],$d['LF']);
  76. $stmt $db->QueryResult("SELECT ID,VALUE FROM DB_SQLITE_T1");
  77. while($t $db->FetchResult($stmt))
  78.   {
  79.   printf("ID=%05s | VALUE=%s%s",$t['ID'],$t['VALUE'],$d['LF']);
  80.   }
  81. $db->FreeResult($stmt);
  82.  
  83. // Finally we drop the table:
  84. $db->Query("DROP TABLE DB_SQLITE_T1");
  85.  
  86. DBFooter($d['LF'],$db);
  87.  
  88. echo($d['LF']);
  89. exit;
  90. ?>

Documentation generated on Sat, 07 Aug 2010 20:01:07 +0200 by phpDocumentor 1.4.3