Source for file functions.inc.php

Documentation is available at functions.inc.php

  1. <?php
  2. /**
  3.  * Set of functions used in the db_SQLite examples.
  4.  * @package db_SQLite
  5.  * @subpackage Examples
  6.  * @author Sascha 'SieGeL' Pfalz <php@saschapfalz.de>
  7.  * @version 0.10 (01-Feb-2009)
  8.  *  $Id: functions.inc.php,v 1.4 2010/08/07 18:00:16 siegel Exp $
  9.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  10.  * @filesource
  11.  */
  12.  
  13. ini_set('error_reporting' E_ALL|E_NOTICE|E_STRICT);
  14.  
  15. /**
  16.  * Load in the class definition based on used PHP version.
  17.  */
  18. require_once('../db_sqlite.class.php');
  19.  
  20. /**
  21.  * Returns an associative array with sapi-type name and required line break char.
  22.  * Use this function to retrieve the required line-break character for both the
  23.  * browser output and shell output. Currently only two keys are included:
  24.  * - "SAPI" => The sapi type of PHP (i.e. "cli")
  25.  * - "LF"   => The line-break character to use (i.e. "<br>")
  26.  * @return array The associative array as described.
  27.  */
  28. function WhichBR()
  29.   {
  30.   $data array();
  31.   $data['SAPI'php_sapi_name();
  32.   switch($data['SAPI'])
  33.     {
  34.     case  'cli':
  35.           $data['LF'"\n";
  36.           $data['HR'"------------------------------------------------------------------------------\n";
  37.           break;
  38.     default:
  39.           $data['LF'"<br>";
  40.           $data['HR'"<hr>";
  41.           break;
  42.     }
  43.   return($data);
  44.   }
  45.  
  46. /**
  47.  * Prints out the amount of queries and the time required to process them.
  48.  * @param string $lf The linefeed character to use.
  49.  * @param mixed &$dbh The database object.
  50.  */
  51. function DBFooter($lf&$dbh)
  52.   {
  53.   printf("%sQueries: %d | Time required: %5.3fs%s",$lf,$dbh->GetQueryCount(),$dbh->GetQueryTime(),$lf);
  54.   }
  55.  
  56. /**
  57.  * Checks if given Object name exists inside the database.
  58.  * If checked object does not exist function can auto create the object if required DML is supplied
  59.  * @param mixed &$dbh The database object.
  60.  * @param string $objectname Name of object to check.
  61.  * @param string $dml_sql Required SQL to create the object if it does not exist.
  62.  * @return bool TRUE if Object exists else false.
  63.  */
  64. function CheckForDBobject(&$dbh$objectname$dml_sql '')
  65.   {
  66.   $result $dbh->Query(sprintf("SELECT COUNT(*) AS CNT FROM sqlite_master WHERE NAME = '%s'",$objectname)SQLITE_ASSOC0$objectname);
  67.   if(intval($result['CNT']0)
  68.     {
  69.     return(true);
  70.     }
  71.   /* If no sql to create object is supplied we return false as object does not exist. */
  72.   if($dml_sql == '')
  73.     {
  74.     return(false);
  75.     }
  76.   /* If $dml_sql != '' we try to create the object in question, and if this does not work we return false. */
  77.   $result $dbh->Query($dml_sql,SQLITE_ASSOC1);
  78.   if(is_resource($result== FALSE)
  79.     {
  80.     $d WhichBR();
  81.     $error $dbh->GetErrorText();
  82.     printf("SQLite ERROR: %s-%s%s",$result,$error,$d['LF']);
  83.     return(false);
  84.     }
  85.   /* All is okay return true now. */
  86.   return(true);
  87.   }
  88. ?>

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