Source for file queries.php

Documentation is available at queries.php

  1. #!/usr/local/bin/php
  2. <?php
  3. /**
  4.  * Examples how to Fetch data from a table.
  5.  * First a single-row function is called (SELECT VERSION()).
  6.  * Second a multi-row function is called (SHOW VARIABLES).
  7.  * Also GetQueryCount() and GetQueryTime() usage is shown.
  8.  * @author Sascha 'SieGeL' Pfalz <php@saschapfalz.de>
  9.  * @package db_MySQL
  10.  * @subpackage Examples
  11.  * @version 0.36 (21-Sep-2008)
  12.  *  $Id: queries.php,v 1.3 2008/09/21 21:07:08 siegel Exp $
  13.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  14.  * @filesource
  15.  */
  16. /**
  17.  */
  18. require('functions.inc.php');
  19. $db new db_MySQL('./dbdefs.inc.php');
  20. $d WhichBR();
  21. if($d['SAPI'!= 'cli')
  22.   {
  23.   echo("<pre>\n");
  24.   }
  25. echo($d['LF']);
  26.  
  27. $db->setErrorHandling(DBOF_SHOW_ALL_ERRORS);
  28. $sock $db->Connect();
  29.  
  30. /*
  31.  * First single-row query. The result of the query "SELECT VERSION()" returns a single
  32.  * string with the current MySQL server version. As the flag "MYSQL_NUM" is given to the
  33.  * class, the result is returned as an numbered array which has only the element 0 containing
  34.  * the Server version.
  35.  */
  36. $version $db->Query("SELECT VERSION()",MYSQL_NUM);
  37. echo($d['LF'].'MySQL Database Version: '.$version[0].$d['LF']);
  38. echo($d['HR'].$d['LF']);
  39.  
  40. // Now Multi-Row query:
  41.  
  42. $query=<<<SQL
  43. SHOW VARIABLES
  44. SQL;
  45.  
  46. $stmt $db->QueryResult($query);
  47.  
  48. /*
  49.  * Dump out the data from the stored resultset $stmt.
  50.  * The SQL statement 'SHOW VARIABLES' returns two values which are then accessable as $t[0] and $t[1],
  51.  * because the flag "MYSQL_NUM" is set, which returns one row of data as numbered array.
  52.  */
  53. while($t $db->FetchResult($stmt,MYSQL_NUM))
  54.   {
  55.   printf("%30s: %s%s",$t[0],$t[1],$d['LF']);
  56.   }
  57. $db->FreeResult($stmt);
  58.  
  59. // Print out some stats:
  60.  
  61. echo($d['LF'].$db->GetQueryCount()." queries took ".round($db->GetQueryTime(),3)." seconds.".$d['LF'].$d['LF']);
  62. $db->Disconnect();
  63. if($d['SAPI'!= 'cli')
  64.   {
  65.   echo("</pre>\n");
  66.   }
  67. ?>

Documentation generated on Sat, 07 Aug 2010 10:18:27 +0200 by phpDocumentor 1.4.3