Source for file mysqldb_class.php

Documentation is available at mysqldb_class.php

  1. <?php
  2. /**
  3.  * Database Class provides a consistent API to communicate with MySQL or Oracle Databases.
  4.  * This one implements the MySQL API.
  5.  * Requires dbdefs.inc.php for global access data (user,pw,host,port,dbname,appname)
  6.  * @author Sascha 'SieGeL' Pfalz <php@saschapfalz.de>
  7.  * @package db_MySQL
  8.  * @version 0.39 (07-Aug-2010)
  9.  *  $Id: mysqldb_class.php,v 1.25 2010/08/07 08:16:14 siegel Exp $
  10.  * @see dbdefs.inc.php
  11.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  12.  * @filesource
  13.  */
  14. /**
  15.  * DEBUG: No Debug Info
  16.  */
  17. if(!defined('DBOF_DEBUGOFF'))
  18.   {
  19.   define('DBOF_DEBUGOFF'    (<< 0));
  20.   }
  21.  
  22. /**
  23.  * DEBUG: Debug on-screen
  24.  */
  25. if(!defined('DBOF_DEBUGSCREEN'))
  26.   {
  27.   define('DBOF_DEBUGSCREEN' (<< 1));
  28.   }
  29.  
  30. /**
  31.  * DEBUG: Debug to error_log()
  32.  */
  33. if(!defined('DBOF_DEBUGSCREEN'))
  34.   {
  35.   define('DBOF_DEBUGFILE'   (<< 2));
  36.   }
  37.  
  38. /**#@+
  39.  * Connect and error handling (V0.28+).
  40.  * If DBOF_SHOW_NO_ERRORS is set and an error occures,
  41.  * the class still reports an an error of course but the error
  42.  * shown is reduced in informational details to avoid showing
  43.  * sensible informations in a productive environment.
  44.  * If DBOF_SHOW_ALL_ERRORS is set the maximum possible details are shown.
  45.  * Set RETURN_ALL_ERRORS if you want to handle errors yourself, in
  46.  * this case the class returns error codes if something goes wrong.
  47.  */
  48. if(!defined('DBOF_SHOW_NO_ERRORS'))
  49.   {
  50.   define('DBOF_SHOW_NO_ERRORS'    0);
  51.   define('DBOF_SHOW_ALL_ERRORS'   1);
  52.   define('DBOF_RETURN_ALL_ERRORS' 2);
  53.   }
  54. /**#@-*/
  55.  
  56. /**#@+
  57.  * These defines are used in DescTable().
  58.  * @see DescTable
  59.  * @since 0.37
  60.  */
  61. define('DBOF_MYSQL_COLNAME' 0);
  62. define('DBOF_MYSQL_COLTYPE' 1);
  63. define('DBOF_MYSQL_COLSIZE' 2);
  64. define('DBOF_MYSQL_COLFLAGS'3);
  65. /**#@-*/
  66.  
  67. /**
  68.  * Main class definition.
  69.  * @package db_MySQL
  70.  */
  71. class db_MySQL
  72.   {
  73.   /** @var mixed $sock Internal connection handle */
  74.   var $sock;
  75.   /** @var string $host Name of database to connect to */
  76.   var $host;
  77.   /** @var integer $port Portnumber to use when connecting to MySQL */
  78.   var $port;
  79.   /** @var string $user Name of database user used for connection */
  80.   var $user;
  81.   /** @var string $pass Password of database user used for connection */
  82.   var $pass;
  83.   /** @var string $database Name of schema to be used */
  84.   var $database;
  85.   /** @var integer $querycounter Counts the processed queries against the database */
  86.   var $querycounter;
  87.   /** @var float $querytime Contains the total SQL execution time in microseconds. */
  88.   var $querytime;
  89.   /** @var string $appname Name of Application that uses this class */
  90.   var $appname;
  91.   /** @var string $classversion Version of this class in format VER.REV */
  92.   var $classversion;
  93.   /** @var string $currentQuery Contains the actual query to be processed. */
  94.   var $currentQuery;
  95.   /** @var integer $showError Flag indicates how the class should interact with errors */
  96.   var $showError;
  97.   /** @var integer $debug Flag indicates debug mode of class */
  98.   var $debug;
  99.   /** @var string $SAPI_type The SAPI type of php (used to detect CLI sapi) */
  100.   var $SAPI_type;
  101.   /** @var string $AdminEmail Email Address for the administrator of this project */
  102.   var $AdminEmail;
  103.   /** @var integer $myErrno Error code of last mysql operation (set in Print_Error()) */
  104.   var $myErrno;
  105.   /** @var string $myErrStr Error string of last mysql operation (set in Print_Error()) */
  106.   var $myErrStr;
  107.   /** @var boolean $usePConnect TRUE = Connect() uses Persistant connection, else new one (Default) */
  108.   var $usePConnect;
  109.   /** @var string $character_set Character set to use. */
  110.   var $characterset;
  111.   /** @var string $locale Locale to use for DATE_FORMAT(), DAYNAME() and MONTHNAME() SQL functions. */
  112.   var $locale;
  113.   /**
  114.    * @var boolean $new_link TRUE => Always create NEW connections, FALSE => Do not create new connections (default)
  115.    * @since 0.38
  116.    */
  117.   var $new_link;
  118.   /**
  119.    * @var integer $num_rows Number of rows returned from a previous SELECT/SHOW statement.
  120.    * @since 0.38
  121.    */
  122.   var $num_rows;
  123.  
  124.   /**
  125.    * Constructor of this class.
  126.    * The constructor takes default values from dbdefs.inc.php.
  127.    * Please see this file for further informations about the setable options.
  128.    * @param string $extconfig Optional other filename for dbdefs.inc.php, defaults to "dbdefs.inc.php".
  129.    * @see dbdefs.inc.php
  130.    */
  131.   function db_MySQL($extconfig='')
  132.     {
  133.     if($extconfig == '')
  134.       {
  135.       require_once('dbdefs.inc.php');
  136.       }
  137.     else
  138.       {
  139.       require($extconfig);
  140.       }
  141.     $this->classversion = '0.39';
  142.  
  143.     $this->host         = '';
  144.     $this->port         = 3306;
  145.     $this->user         = '';
  146.     $this->pass         = '';
  147.     $this->database     = '';
  148.     $this->appname      = MYSQLAPPNAME;
  149.  
  150.     $this->sock         = 0;
  151.     $this->querycounter = 0;
  152.     $this->querytime    = 0.000;
  153.     $this->currentQuery = '';
  154.     $this->debug        = 0;
  155.     $this->myErrno      = 0;
  156.     $this->MyErrStr     '';
  157.     $this->AdminEmail   = (isset($_SERVER['SERVER_ADMIN'])) $_SERVER['SERVER_ADMIN''';
  158.     $this->SAPI_type    = @php_sapi_name();         // May contain 'cli', in this case disable HTML errors!
  159.     $this->usePConnect  = FALSE;                    // Set to TRUE to use Persistant connections
  160.     $this->characterset = '';                       // Will be filled from define MYSQLDB_CHARACTERSET during Connect()
  161.     $this->locale       = '';                       // Will be filled from define MYSQLDB_TIME_NAMES during Connect()
  162.     $this->new_link     = FALSE;                    // Same value as all previous releases, filled by MYSQLDB_NEW_LINK define
  163.     $this->num_rows     = 0;                        // Number of rows returned from SELECT & SHOW statements.
  164.  
  165.     if(!defined('MYSQLAPPNAME'))
  166.       {
  167.       $this->Print_Error('dbdefs.inc.php not found/wrong configured! Please check Class installation!');
  168.       }
  169.  
  170.     if(defined('DB_ERRORMODE'))                       // You can set a default behavour for error handling in debdefs.inc.php
  171.       {
  172.       $this->setErrorHandling(DB_ERRORMODE);
  173.       }
  174.     else
  175.       {
  176.       $this->setErrorHandling(DBOF_SHOW_NO_ERRORS);   // Default is not to show too much informations
  177.       }
  178.  
  179.     if(defined('MYSQLDB_ADMINEMAIL'))
  180.       {
  181.       $this->AdminEmail = MYSQLDB_ADMINEMAIL;         // If set use this address instead of default webmaster
  182.       }
  183.  
  184.     // Check if user requested persistant connection per default in dbdefs.inc.php
  185.     if(defined('MYSQLDB_USE_PCONNECT'&& MYSQLDB_USE_PCONNECT != 0)
  186.       {
  187.       $this->usePConnect = TRUE;
  188.       }
  189.  
  190.     // Check if user wants to have set a specific character set with 'SET NAMES <cset>'
  191.     if(defined('MYSQLDB_CHARACTERSET'&& MYSQLDB_CHARACTERSET != '')
  192.       {
  193.       $this->characterset = MYSQLDB_CHARACTERSET;
  194.       }
  195.  
  196.     // Check if user wants to have set a specific locale with 'SET SET lc_time_names = <locale>;'
  197.     if(defined('MYSQLDB_TIME_NAMES'&& MYSQLDB_TIME_NAMES != '')
  198.       {
  199.       $this->locale = MYSQLDB_TIME_NAMES;
  200.       }
  201.  
  202.     // Check if user defined a new behavour for NEW_LINK parameter in mysql_connect()
  203.     if(defined('MYSQLDB_NEW_LINK'&& is_bool(MYSQLDB_NEW_LINK))
  204.       {
  205.       $this->new_link = MYSQLDB_NEW_LINK;
  206.       }
  207.     }
  208.  
  209.   /**
  210.    * Performs the connection to MySQL.
  211.    * If anything goes wrong calls Print_Error().
  212.    * You should set the defaults for your connection by setting
  213.    * user,pass,host and database in dbdefs.inc.php and leave
  214.    * connect() parameters empty.
  215.    * If MYSQLDB_CHARACTERSET define is set a "SET NAMES '<charset>'; is used straight after connecting.
  216.    * @param string $user Username used to connect to DB
  217.    * @param string $pass Password to use for given username
  218.    * @param string $host Hostname of database to connect to
  219.    * @param integer $port TCP port to use for connection. Defaults to 3306.
  220.    * @param string $db Schema to use on MySQL DB Server
  221.    * @return mixed Either the DB connection handle or NULL in case of an error.
  222.    * @see dbdefs.inc.php
  223.    * @see mysql_connect()
  224.    * @see mysql_pconnect()
  225.    * @see mysql_select_db()
  226.    */
  227.   function Connect($user='',$pass='',$host='',$db='',$port 0)
  228.     {
  229.     if($this->sock)
  230.       {
  231.       return($this->sock);
  232.       }
  233.     if($user!='')
  234.       {
  235.       $this->user = $user;
  236.       }
  237.     else
  238.       {
  239.       $this->user = MYSQLDB_USER;
  240.       }
  241.     if($pass!='')
  242.       {
  243.       $this->pass = $pass;
  244.       }
  245.     else
  246.       {
  247.       $this->pass = MYSQLDB_PASS;
  248.       }
  249.     if($host!='')
  250.       {
  251.       $this->host = $host;
  252.       }
  253.     else
  254.       {
  255.       $this->host = MYSQLDB_HOST;
  256.       }
  257.     if($db!='')
  258.       {
  259.       $this->database = $db;
  260.       }
  261.     else
  262.       {
  263.       $this->database = MYSQLDB_DATABASE;
  264.       }
  265.     if(!$port)
  266.       {
  267.       if(defined('MYSQLDB_PORT'))
  268.         {
  269.         $this->port = MYSQLDB_PORT;
  270.         }
  271.       else
  272.         {
  273.         $this->port = 3306;
  274.         }
  275.       }
  276.     else
  277.       {
  278.       $this->port = $port;
  279.       }
  280.     // Append port number ONLY if hostname doesn't start with a slash (which is a pipe!)
  281.     if(strlen($this->host>= && $this->host[0!= '/')
  282.       {
  283.       $this->host = $this->host.':'.$this->port;
  284.       }
  285.     $start $this->getmicrotime();
  286.     $this->printDebug('mysql_connect('.sprintf("%s/%s@%s",$this->user,$this->pass,$this->host).')');
  287.     if($this->usePConnect == FALSE)
  288.       {
  289.       if(version_compare('4.3.0',@phpversion()) 0)
  290.         {
  291.         $this->sock = @mysql_connect($this->host,$this->user,$this->pass,$this->new_link);
  292.         }
  293.       else
  294.         {
  295.         $this->sock = @mysql_connect($this->host,$this->user,$this->pass);
  296.         }
  297.       }
  298.     else    // Persistant connection requested:
  299.       {
  300.       if(version_compare('4.3.0',@phpversion()) 0)
  301.         {
  302.         $this->sock = @mysql_pconnect($this->host,$this->user,$this->pass,$this->new_link);
  303.         }
  304.       else
  305.         {
  306.         $this->sock = @mysql_pconnect($this->host,$this->user,$this->pass);
  307.         }
  308.       }
  309.     if(!$this->sock)
  310.       {
  311.       $this->Print_Error('Connect(): Connection to '.$this->host.' failed!');
  312.       return(0);
  313.       }
  314.     $this->printDebug('mysql_select_db('.sprintf("%s",$this->database).')');
  315.     if(!@mysql_select_db($this->database,$this->sock))
  316.       {
  317.       $this->Print_Error('Connect(): SelectDB(\''.$this->database.'\') failed!');
  318.       return(0);
  319.       }
  320.     $this->querytime+= ($this->getmicrotime($start);
  321.     if($this->characterset != '')
  322.       {
  323.       $rc $this->Query("SET NAMES '".$this->characterset."'",MYSQL_NUM,1);
  324.       if($rc != 1)
  325.         {
  326.         $this->Print_Error('Connect(): Error while trying to set character set "'.$this->characterset.'" !!!');
  327.         return(0);
  328.         }
  329.       }
  330.     if($this->locale != '')
  331.       {
  332.       $rc $this->Query("SET lc_time_names='".$this->locale."'",MYSQL_NUM,1);
  333.       if($rc != 1)
  334.         {
  335.         $this->Print_Error('Connect(): Error while trying to set lc_time_names to "'.$this->locale.'" !!!');
  336.         return(0);
  337.         }
  338.       }
  339.     return($this->sock);
  340.     }
  341.  
  342.   /**
  343.    * Disconnects from MySQL.
  344.    * You may optionally pass an external link identifier.
  345.    * @param mixed $other_sock Optionally your own connection handle to close, else internal will be used
  346.    * @see mysql_close()
  347.    */
  348.   function Disconnect($other_sock=-1)
  349.     {
  350.     if($other_sock!=-1)
  351.       {
  352.       @mysql_close($other_sock);
  353.       }
  354.     else
  355.       {
  356.       if($this->sock)
  357.         {
  358.         @mysql_close($this->sock);
  359.         $this->sock = 0;
  360.         $this->num_rows = 0;
  361.         }
  362.       }
  363.     $this->currentQuery = '';
  364.     }
  365.  
  366.   /**
  367.    * Prints out MySQL Error in own <div> container and exits.
  368.    * Please note that this function does not return as long as you have not set DBOF_RETURN_ALL_ERRORS!
  369.    * @param string $ustr User-defined Error string to show
  370.    * @param mixed $var2dump Optionally a variable to print out with print_r()
  371.    * @see print_r()
  372.    * @see mysql_errno()
  373.    * @see mysql_error()
  374.    */
  375.   function Print_Error($ustr="",$var2dump="")
  376.     {
  377.     $errnum   @mysql_errno();
  378.     $errstr   @mysql_error();
  379.     $filename basename($_SERVER['SCRIPT_FILENAME']);
  380.     $this->myErrno = $errnum;
  381.     $this->myErrStr$errstr;
  382.     if($errstr=='')
  383.       {
  384.       $errstr 'N/A';
  385.       }
  386.     if($errnum=='')
  387.       {
  388.       $errnum = -1;
  389.       }
  390.     @error_log($this->appname.': Error in '.$filename.': '.$ustr.' ('.chop($errstr).')',0);
  391.     if($this->showError == DBOF_RETURN_ALL_ERRORS)
  392.       {
  393.       return($errnum);      // Return the error number
  394.       }
  395.     $this->SendMailOnError($errnum,$errstr,$ustr);
  396.     $crlf "\n";
  397.     $space" ";
  398.     if($this->SAPI_type != 'cli')
  399.       {
  400.       $crlf "<br>\n";
  401.       $space"&nbsp;";
  402.       echo("<br>\n<div align=\"left\" style=\"background-color: #EEEEEE; color:#000000\" class=\"TB\">\n");
  403.       echo("<font color=\"red\" face=\"Arial, Sans-Serif\"><b>".$this->appname.": Database Error occured!</b></font><br>\n<br>\n<code>\n");
  404.       }
  405.     else
  406.       {
  407.       echo("\n!!! ".$this->appname.": Database Error occured !!!\n\n");
  408.       }
  409.     echo($space."CODE: ".$errnum.$crlf);
  410.     echo($space."DESC: ".$errstr.$crlf);
  411.     echo($space."FILE: ".$filename.$crlf);
  412.     if($this->showError == DBOF_SHOW_ALL_ERRORS)
  413.       {
  414.       if($this->currentQuery!="")
  415.         {
  416.         echo("QUERY: ".$this->currentQuery.$crlf);
  417.         }
  418.       echo($space."QCNT: ".$this->querycounter.$crlf);
  419.       if($ustr!='')
  420.         {
  421.         echo($space."INFO: ".$ustr.$crlf);
  422.         }
  423.       if($var2dump!='')
  424.         {
  425.         echo($space.'DUMP: ');
  426.         if(is_array($var2dump))
  427.           {
  428.           if($this->SAPI_type != 'cli')
  429.             {
  430.             echo('<pre>');
  431.             print_r($var2dump);
  432.             echo("</pre>\n");
  433.             }
  434.           else
  435.             {
  436.             print_r($var2dump);
  437.             }
  438.           }
  439.         else
  440.           {
  441.           echo($var2dump.$crlf);
  442.           }
  443.         }
  444.       }
  445.     if($this->SAPI_type != 'cli')
  446.       {
  447.       echo("<br>\nPlease inform <a href=\"mailto:".$this->AdminEmail."\">".$this->AdminEmail."</a> about this problem.");
  448.       echo("</code>\n");
  449.       echo("</div>\n");
  450.       echo("<div align=\"right\"><small>PHP v".phpversion()." / MySQL Class v".$this->classversion."</small></div>\n");
  451.       }
  452.     else
  453.       {
  454.       echo("\nPlease inform ".$this->AdminEmail." about this problem.\n\nRunning on PHP V".phpversion()." / MySQL Class v".$this->classversion."\n");
  455.       }
  456.     $this->Disconnect();
  457.     exit;
  458.     }
  459.  
  460.   /**
  461.    * Performs a single row query.
  462.    *
  463.    * Resflag can be MYSQL_NUM or MYSQL_ASSOC depending on what kind of array you want to be returned.
  464.    * Since v0.38 the value of mysql_num_rows() is stored in self::num_rows if the executed query was either a SELECT or a SHOW statement.
  465.    * @param string $querystring The query to be executed
  466.    * @param integer $resflag Decides how the result should be returned:
  467.    *   - MYSQL_ASSOC = Data is returned as assoziative array
  468.    *   - MYSQL_NUM   = Data is returned as numbered array
  469.    * @param integer $no_exit Decides how the class should react on errors.
  470.    *                          If you set this to 1 the class won't automatically exit
  471.    *                          on an error but instead return the mysql_errno value.
  472.    *                          Default of 0 means that the class calls Print_Error()
  473.    *                          and exists.
  474.    * @return mixed Either the result of the query or an error code or no return value at all
  475.    * @see Print_Error()
  476.    * @see mysql_query()
  477.    * @see mysql_fetch_array()
  478.    * @see mysql_free_result()
  479.    * @see mysql_num_rows()
  480.    */
  481.   function Query($querystring,$resflag MYSQL_ASSOC$no_exit 0)
  482.     {
  483.     if(!$this->sock)
  484.       {
  485.       return($this->Print_Error('Query(): No active Connection!',$querystring));
  486.       }
  487.     if($this->debug)
  488.       {
  489.       $this->PrintDebug($querystring);
  490.       }
  491.     $this->currentQuery = $querystring;
  492.     if($this->showError == DBOF_RETURN_ALL_ERRORS)
  493.       {
  494.       $no_exit 1;  // Override if user has set master define
  495.       }
  496.     $start $this->getmicrotime();
  497.     $res mysql_query($querystring,$this->sock);
  498.     if($res == false)
  499.       {
  500.       if($no_exit)
  501.         {
  502.         $reterror @mysql_errno();
  503.         return($reterror);
  504.         }
  505.       else
  506.         {
  507.         return($this->Print_Error("Query('".$querystring."') failed!"));
  508.         }
  509.       }
  510.     $this->querycounter++;
  511.     if($this->IsQueryWithResult($querystring)==TRUE)
  512.       {
  513.       $this->num_rows = @mysql_num_rows($res);
  514.       $retdata @mysql_fetch_array($res,$resflag);
  515.       @mysql_free_result($res);
  516.       $this->querytime+= ($this->getmicrotime($start);
  517.       return($retdata);
  518.       }
  519.     else
  520.       {
  521.       $this->querytime+= ($this->getmicrotime($start);
  522.       return($res);
  523.       }
  524.     }
  525.  
  526.   /**
  527.    * Private function checks if a given query is not a DML command.
  528.    * Currently checks for SELECT,SHOW,EXPLAIN,DESCRIBE,OPTIMIZE,ANALYZE,CHECK
  529.    * commands, as these commands all can return a result set.
  530.    * @param string $querystring The query to check.
  531.    * @return bool Returns TRUE if query can return a result set, else returns FALSE for DML or other unknown commands (i.e. SET).
  532.    */
  533.   function IsQueryWithResult($querystring)
  534.     {
  535.     $querypart substr($querystring,0,10);
  536.     // Check if query requires returning the results or just the result of the query call:
  537.     ifStriStr($querypart,'SELECT '||
  538.         StriStr($querypart,'SHOW '||
  539.         StriStr($querypart,'EXPLAIN '||
  540.         StriStr($querypart,'DESCRIBE '||
  541.         StriStr($querypart,'OPTIMIZE '||
  542.         StriStr($querypart,'ANALYZE '||
  543.         StriStr($querypart,'CHECK ')
  544.       )
  545.       {
  546.       return(TRUE);
  547.       }
  548.     return(FALSE);
  549.     }
  550.  
  551.   /**
  552.    * Performs a multi-row query and returns result identifier.
  553.    * @param string $querystring The Query to be executed
  554.    * @param integer $no_exit The error indicator flag, can be one of:
  555.    *   - 0 = (Default), In case of an error Print_Error is called and script terminates
  556.    *   - 1 = In case of an error this function returns the error from mysql_errno()
  557.    * @return mixed A resource identifier or an errorcode (if $no_exit = 1)
  558.    * @see mysql_query()
  559.    */
  560.   function QueryResult($querystring$no_exit 0)
  561.     {
  562.     if(!$this->sock)
  563.       {
  564.       return($this->Print_Error('QueryResult(): No active Connection!',$querystring));
  565.       }
  566.     if($this->debug)
  567.       {
  568.       $this->PrintDebug($querystring);
  569.       }
  570.     $this->currentQuery = $querystring;
  571.     $start $this->getmicrotime();
  572.     $res @mysql_query($querystring,$this->sock);
  573.     $this->querycounter++;
  574.     if($res == false)
  575.       {
  576.       if($no_exit)
  577.         {
  578.         $reterror @mysql_errno();
  579.         $this->querytime+= ($this->getmicrotime($start);
  580.         return($reterror);
  581.         }
  582.       else
  583.         {
  584.         return($this->Print_Error("QueryResult('".$querystring."') failed!"));
  585.         }
  586.       }
  587.     if($this->IsQueryWithResult($querystring)==TRUE)
  588.       {
  589.       $this->num_rows = @mysql_num_rows($res);
  590.       }
  591.     $this->querytime+= ($this->getmicrotime($start);
  592.     return($res);
  593.     }
  594.  
  595.   /**
  596.    * Fetches next row from result handle.
  597.    * Returns either numeric (MYSQL_NUM) or associative (MYSQL_ASSOC) array
  598.    * for one data row as pointed to by result var.
  599.    * @param mixed $result The resource identifier as returned by QueryResult()
  600.    * @param integer $resflag How you want the data to be returned:
  601.    *   - MYSQL_ASSOC = Data is returned as assoziative array
  602.    *   - MYSQL_NUM   = Data is returned as numbered array
  603.    * @return array One row of the resulting query or NULL if there are no data anymore
  604.    * @see mysql_fetch_array()
  605.    * @see QueryResult()
  606.    */
  607.   function FetchResult($result,$resflag MYSQL_ASSOC)
  608.     {
  609.     if(!$result)
  610.       {
  611.       return($this->Print_Error('FetchResult(): No valid result handle!'));
  612.       }
  613.     $start $this->getmicrotime();
  614.     $resar @mysql_fetch_array($result,$resflag);
  615.     $this->querytime+= ($this->getmicrotime($start);
  616.     return($resar);
  617.     }
  618.  
  619.   /**
  620.    * Frees result returned by QueryResult().
  621.    * It is a good programming practise to give back what you have taken, so after processing
  622.    * your Multi-Row query with FetchResult() finally call this function to free the allocated
  623.    * memory.
  624.    *
  625.    * @param mixed $result The resource identifier you want to be freed.
  626.    * @return mixed The resulting code of mysql_free_result (can be ignored).
  627.    * @see mysql_free_result()
  628.    * @see QueryResult()
  629.    * @see FetchResult()
  630.    */
  631.   function FreeResult($result)
  632.     {
  633.     $this->currentQuery = '';
  634.     $start $this->getmicrotime();
  635.     $myres @mysql_free_result($result);
  636.     $this->querytime+= ($this->getmicrotime($start);
  637.     return($myres);
  638.     }
  639.  
  640.   /**
  641.    * Returns MySQL Server Version.
  642.    * Opens an own connection if no active one exists.
  643.    * @return string MySQL Server Version
  644.    */
  645.   function Version()
  646.     {
  647.     $weopen 0;
  648.     if(!$this->sock)
  649.       {
  650.       $this->connect();
  651.       $weopen 1;
  652.       }
  653.     $ver $this->Query('SELECT VERSION()',MYSQL_NUM);
  654.     if($weopen)
  655.       {
  656.       $this->Disconnect();
  657.       }
  658.     return($ver[0]);
  659.     }
  660.  
  661.   /**
  662.    * Returns amount of queries executed by this class.
  663.    * @return integer Querycount
  664.    */
  665.   function GetQueryCount()
  666.     {
  667.     return($this->querycounter);
  668.     }
  669.  
  670.   /**
  671.    * Returns amount of time spend on queries executed by this class.
  672.    * @return float Time in seconds.msecs spent in executin MySQL code.
  673.    */
  674.   function GetQueryTime()
  675.     {
  676.     return($this->querytime);
  677.     }
  678.  
  679.   /**
  680.    * Commits current transaction.
  681.    * Note: Requires transactional tables, else does nothing!
  682.    */
  683.   function Commit()
  684.     {
  685.     if($this->debug)
  686.       {
  687.       $this->PrintDebug('COMMIT called');
  688.       }
  689.     $this->Query('COMMIT;');
  690.     }
  691.  
  692.   /**
  693.    * Rollback current transaction.
  694.    * Note: Requires transactional tables, else does nothing!
  695.    */
  696.   function Rollback()
  697.     {
  698.     if($this->debug)
  699.       {
  700.       $this->PrintDebug('ROLLBACK called');
  701.       }
  702.     $this->Query('ROLLBACK;');
  703.     }
  704.  
  705.   /**
  706.    * Function allows debugging of SQL Queries.
  707.    * $state can have these values:
  708.    * - DBOF_DEBUGOFF    = Turn off debugging
  709.    * - DBOF_DEBUGSCREEN = Turn on debugging on screen (every Query will be dumped on screen)
  710.    * - DBOF_DEBUFILE    = Turn on debugging on PHP errorlog
  711.    * You can mix the debug levels by adding the according defines!
  712.    * @param integer $state The DEBUG Level you want to be set
  713.    */
  714.   function SetDebug($state)
  715.     {
  716.     $this->debug = $state;
  717.     }
  718.  
  719.   /**
  720.    * Returns the current debug setting.
  721.    * @return integer The debug setting (bitmask)
  722.    * @see SetDebug()
  723.    */
  724.   function GetDebug()
  725.     {
  726.     return($this->debug);
  727.     }
  728.  
  729.   /**
  730.    * Handles output according to internal debug flag.
  731.    * @param string $msg The Text to be included in the debug message.
  732.    * @see error_log()
  733.    */
  734.   function PrintDebug($msg)
  735.     {
  736.     if(!$this->debug)
  737.       {
  738.       return;
  739.       }
  740.     if($this->SAPI_type != 'cli')
  741.       {
  742.       $formatstr "<div align=\"left\" style=\"background-color:#ffffff; color:#000000;\"><pre>DEBUG: %s</pre></div>\n";
  743.       }
  744.     else
  745.       {
  746.       $formatstr =  "DEBUG: %s\n";
  747.       }
  748.     if($this->debug DBOF_DEBUGSCREEN)
  749.       {
  750.       @printf($formatstr,$msg);
  751.       }
  752.     if($this->debug DBOF_DEBUGFILE)
  753.       {
  754.       @error_log('DEBUG: '.$msg,0);
  755.       }
  756.     }
  757.  
  758.   /**
  759.    * Returns version of this class.
  760.    * @return string The version of this class.
  761.    */
  762.   function GetClassVersion()
  763.     {
  764.     return($this->classversion);
  765.     }
  766.  
  767.   /**
  768.    * Returns last used auto_increment id.
  769.    * @param mixed $extsock Optionally an external MySQL socket to use. If not given the internal socket is used.
  770.    * @return integer The last automatic insert id that was assigned by the MySQL server.
  771.    * @see mysql_insert_id()
  772.    */
  773.   function LastInsertId($extsock=-1)
  774.     {
  775.     if($extsock==-1)
  776.       {
  777.       return(@mysql_insert_id($this->sock));
  778.       }
  779.     else
  780.       {
  781.       return(@mysql_insert_id($extsock));
  782.       }
  783.     }
  784.  
  785.   /**
  786.    * Returns count of affected rows by last DML operation.
  787.    * @param mixed $extsock Optionally an external MySQL socket to use. If not given the internal socket is used.
  788.    * @return integer The number of affected rows by previous DML operation.
  789.    * @see mysql_affected_rows()
  790.    * @see NumRows()
  791.    */
  792.   function AffectedRows($extsock=-1)
  793.     {
  794.     if($extsock==-1)
  795.       {
  796.       return(@mysql_affected_rows($this->sock));
  797.       }
  798.     else
  799.       {
  800.       return(@mysql_affected_rows($extsock));
  801.       }
  802.     }
  803.  
  804.   /**
  805.    * Converts a MySQL default Datestring (YYYY-MM-DD HH:MI:SS) into a strftime() compatible format.
  806.    * You can use all format tags that strftime() supports, this function simply converts the mysql
  807.    * date string into a timestamp which is then passed to strftime together with your supplied
  808.    * format. The converted datestring is then returned.
  809.    * Please do not use this as default date converter, always use DATE_FORMAT() inside a query
  810.    * whenever possible as this is much faster than using this function! Only if you cannot use
  811.    * the MySQL SQL Date converting functions consider using this function.
  812.    * @param string $mysqldate The MySQL default datestring in format YYYY-MM-DD HH:MI:SS
  813.    * @param string $fmtstring A strftime() compatible format string.
  814.    * @return string The converted date string.
  815.    * @see strftime()
  816.    * @see mktime()
  817.    */
  818.   function ConvertMySQLDate($mysqldate,$fmtstring)
  819.     {
  820.     $dt explode(' ',$mysqldate);  // Split in date/time
  821.     $dp explode('-',$dt[0]);                                  // Split date
  822.     $tp explode(':',$dt[1]);                                  // Split time
  823.     $ts mktime(intval($tp[0]),intval($tp[1]),intval($tp[2]),intval($dp[1]),intval($dp[2]),intval($dp[0]));    // Create time stamp
  824.     if($fmtstring=='')
  825.       {
  826.       $fmtstring '%c';
  827.       }
  828.     return(strftime($fmtstring,$ts));
  829.     }
  830.  
  831.   /**
  832.    * Returns microtime in format s.mmmmm.
  833.    * Used to measure SQL execution time.
  834.    * @return float the current time in microseconds.
  835.    */
  836.   function getmicrotime()
  837.     {
  838.     list($usec$secexplode(" ",microtime());
  839.     return ((float)$usec + (float)$sec);
  840.     }
  841.  
  842.   /**
  843.    * Allows to set the handling of errors.
  844.    *
  845.    * - DBOF_SHOW_NO_ERRORS    => Show no security-relevant informations.
  846.    * - DBOF_SHOW_ALL_ERRORS   => Show all errors (useful for develop).
  847.    * - DBOF_RETURN_ALL_ERRORS => No error/autoexit, just return the mysql_error code.
  848.    * @param integer $val The Error Handling mode you wish to use.
  849.    * @return integer The previous value for error handling.
  850.    * @since 0.28
  851.    */
  852.   function setErrorHandling($val)
  853.     {
  854.     $oldval $this->showError;
  855.     $this->showError = $val;
  856.     return($oldval);
  857.     }
  858.  
  859.   /**
  860.    * Returns current connection handle.
  861.    * Returns either the internal connection socket or -1 if no active handle exists.
  862.    * Useful if you want to work with mysql* functions in parallel to this class.
  863.    * @return mixed Internal socket value
  864.    * @since 0.32
  865.    */
  866.   function GetConnectionHandle()
  867.     {
  868.     return($this->sock);
  869.     }
  870.  
  871.   /**
  872.    * Allows to set internal socket to external value.
  873.    * @param mixed New socket handle to set (as returned from mysql_connect())
  874.    * @see mysql_connect()
  875.    * @since 0.32
  876.    */
  877.   function SetConnectionHandle($extsock)
  878.     {
  879.     $this->sock = $extsock;
  880.     }
  881.  
  882.   /**
  883.    * Checks if we are already connected to our database.
  884.    * If not terminates by calling Print_Error().
  885.    * @see Print_Error()
  886.    * @since 0.37
  887.    */
  888.   function checkSock()
  889.     {
  890.     if(!$this->sock)
  891.       {
  892.       return($this->Print_Error('<b>!!! NOT CONNECTED TO AN MYSQL DATABASE !!!</b>'));
  893.       }
  894.     }
  895.  
  896.   /**
  897.    * Send error email if programmer has defined a valid email address and
  898.    * enabled it with the define MYSQLDB_SENTMAILONERROR.
  899.    * @param integer $merrno MySQL errno number
  900.    * @param string $merrstr MySQL error description
  901.    * @param string $uerrstr User-supplied error description
  902.    * @see dbdefs.inc.php
  903.    * @see mail()
  904.    */
  905.   function SendMailOnError($merrno,$merrstr,$uerrstr)
  906.     {
  907.     if(!defined('MYSQLDB_SENTMAILONERROR'|| MYSQLDB_SENTMAILONERROR == || $this->AdminEmail == '')
  908.       {
  909.       return;
  910.       }
  911.     $sname (isset($_SERVER['SERVER_NAME'])) $_SERVER['SERVER_NAME''';
  912.     $saddr (isset($_SERVER['SERVER_ADDR'])) $_SERVER['SERVER_ADDR''';
  913.     $raddr (isset($_SERVER['REMOTE_ADDR'])) $_SERVER['REMOTE_ADDR''';
  914.     if($sname == '')
  915.       {
  916.       $server 'n/a';
  917.       }
  918.     else
  919.       {
  920.       $server$sname." (".$saddr.")";
  921.       }
  922.     $uagent  (isset($_SERVER['HTTP_USER_AGENT'])) $_SERVER['HTTP_USER_AGENT''';
  923.     if($uagent == '')
  924.       {
  925.       $uagent 'n/a';
  926.       }
  927.     if($raddr != '')
  928.       {
  929.       $clientip $raddr." (".@gethostbyaddr($raddr).")";
  930.       }
  931.     else
  932.       {
  933.       $clientip 'n/a';
  934.       }
  935.     $message "MySQLDB Class v".$this->classversion.": Error occured on ".date('r')." !!!\n\n";
  936.     $message.= "      APPLICATION: ".$this->appname."\n";
  937.     $message.= "  AFFECTED SERVER: ".$server."\n";
  938.     $message.= "       USER AGENT: ".$uagent."\n";
  939.     $message.= "       PHP SCRIPT: ".$_SERVER['SCRIPT_FILENAME']."\n";
  940.     $message.= "   REMOTE IP ADDR: ".$clientip."\n";
  941.     $message.= "    DATABASE DATA: ".$this->user." @ ".$this->host."\n";
  942.     $message.= "SQL ERROR MESSAGE: ".$merrstr."\n";
  943.     $message.= "   SQL ERROR CODE: ".$merrno."\n";
  944.     $message.= "    QUERY COUNTER: ".$this->querycounter."\n";
  945.     $message.= "         INFOTEXT: ".$uerrstr."\n";
  946.     if($this->currentQuery != '')
  947.       {
  948.       $message.= "        SQL QUERY:\n";
  949.       $message.= "------------------------------------------------------------------------------------\n";
  950.       $message.= $this->currentQuery."\n";
  951.       }
  952.     $message.= "------------------------------------------------------------------------------------\n";
  953.     if(defined('MYSQLDB_MAIL_EXTRAARGS'&& MYSQLDB_MAIL_EXTRAARGS != '')
  954.       {
  955.       @mail($this->AdminEmail,'MySQLDB Class v'.$this->classversion.' ERROR #'.$merrno.' OCCURED!',$message,MYSQLDB_MAIL_EXTRAARGS);
  956.       }
  957.     else
  958.       {
  959.       @mail($this->AdminEmail,'MySQLDB Class v'.$this->classversion.' ERROR #'.$merrno.' OCCURED!',$message);
  960.       }
  961.     }
  962.  
  963.   /**
  964.    * Retrieve last mysql error number.
  965.    * @param mixed $other_sock Optionally your own connection handle to check, else internal will be used.
  966.    * @return integer The MySQL error number of the last operation.
  967.    * @see mysql_errno()
  968.    * @since 0.33
  969.    */
  970.   function GetErrno($other_sock = -1)
  971.     {
  972.     if$other_sock == -)
  973.       {
  974.       if(!$this->sock)
  975.         {
  976.         return($this->myErrno);
  977.         }
  978.       else
  979.         {
  980.         return(@mysql_errno($this->sock));
  981.         }
  982.       }
  983.     else
  984.       {
  985.       if(!$other_sock)
  986.         {
  987.         return($this->myErrno);
  988.         }
  989.       else
  990.         {
  991.         return(@mysql_errno($other_sock));
  992.         }
  993.       }
  994.     }
  995.  
  996.   /**
  997.    * Retrieve last mysql error description.
  998.    * @param mixed $other_sock Optionally your own connection handle to check, else internal will be used.
  999.    * @return string The MySQL error description of the last operation.
  1000.    * @see mysql_error()
  1001.    * @since 0.33
  1002.    */
  1003.   function GetErrorText($other_sock = -1)
  1004.     {
  1005.     if$other_sock == -)
  1006.       {
  1007.       if(!$this->sock)
  1008.         {
  1009.         return($this->myErrStr);
  1010.         }
  1011.       else
  1012.         {
  1013.         return(@mysql_error($this->sock));
  1014.         }
  1015.       }
  1016.     else
  1017.       {
  1018.       if(!$other_sock)
  1019.         {
  1020.         return($this->myErrStr);
  1021.         }
  1022.       else
  1023.         {
  1024.         return(@mysql_error($other_sock));
  1025.         }
  1026.       }
  1027.     }
  1028.  
  1029.   /**
  1030.    * Sets connection behavour.
  1031.    * If FALSE class uses mysql_connect to connect.
  1032.    * If TRUE class uses mysql_pconnect to connect (Persistant connection).
  1033.    * @param boolean The new setting for persistant connections.
  1034.    * @return boolean The previous state.
  1035.    * @since 0.35
  1036.    */
  1037.   function setPConnect($conntype)
  1038.     {
  1039.     if(is_bool($conntype)==FALSE)
  1040.       {
  1041.       return($this->usePConnect);
  1042.       }
  1043.     $oldtype $this->usePConnect;
  1044.     $this->usePConnect = $conntype;
  1045.     return($oldtype);
  1046.     }
  1047.  
  1048.   /**
  1049.    * Escapes a given string with the 'mysql_real_escape_string' method.
  1050.    * Always use this function to avoid SQL injections when adding dynamic data to MySQL!
  1051.    * This function also handles the settings for magic_quotes_gpc/magic_quotes_sybase, if
  1052.    * these settings are enabled this function uses stripslashes() first.
  1053.    * @param string $str The string to escape.
  1054.    * @return string The escaped string.
  1055.    * @since 0.35
  1056.    */
  1057.   function EscapeString($str)
  1058.     {
  1059.     $data $str;
  1060.     if(get_magic_quotes_gpc())
  1061.       {
  1062.       $data stripslashes($data);
  1063.       }
  1064.     $link get_resource_type($this->sock);
  1065.     if($this->sock && substr($link,0,5=='mysql')
  1066.       {
  1067.       return(mysql_real_escape_string($data,$this->sock));
  1068.       }
  1069.     else
  1070.       {
  1071.       return(mysql_escape_string($data));
  1072.       }
  1073.     }
  1074.  
  1075.   /**
  1076.    * Method to set the time_names setting of the MySQL Server.
  1077.    * Pass it a valid locale string to change the locale setting of MySQL.
  1078.    * Note that this is supported only since 5.0.25 of MySQL!
  1079.    * @param string $locale A locale string for the language you want to set, i.e. 'de_DE'.
  1080.    * @return integer 0 If an error occures or 1 if change was successful.
  1081.    * @since 0.36
  1082.    */
  1083.   function set_TimeNames($locale)
  1084.     {
  1085.     $rc $this->Query("SET lc_time_names='".$locale."'",MYSQL_NUM,1);
  1086.     if($rc != 1)
  1087.       {
  1088.       $this->Print_Error('set_TimeNames(): Error while trying to set lc_time_names to "'.$locale.'" !!!');
  1089.       return(0);
  1090.       }
  1091.     $this->locale = $locale;
  1092.     return(1);
  1093.     }
  1094.  
  1095.   /**
  1096.    * Method to return the current MySQL setting for the lc_time_names variable.
  1097.    * @return string The current setting for the lc_time_names variable.
  1098.    * @since 0.36
  1099.    */
  1100.   function get_TimeNames()
  1101.     {
  1102.     $data $this->Query("SELECT @@lc_time_names",MYSQL_NUM,1);
  1103.     if(is_array($data)==false)
  1104.       {
  1105.       $this->Print_Error('get_TimeNames(): Error while trying to retrieve the lc_time_names variable !!!');
  1106.       return(0);
  1107.       }
  1108.     return($data[0]);
  1109.     }
  1110.  
  1111.   /**
  1112.    * Method to set the character set of the current connection.
  1113.    * You must specify a valid character set name, else the class will report an error.
  1114.    * See http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html for a list of supported character sets.
  1115.    * @param string $charset The charset to set on the MySQL server side.
  1116.    * @return integer 1 If all works, else 0 in case of an error.
  1117.    * @since 0.36
  1118.    */
  1119.   function set_CharSet($charset)
  1120.     {
  1121.     $rc $this->Query("SET NAMES '".$charset."'",MYSQL_NUM,1);
  1122.     if($rc != 1)
  1123.       {
  1124.       $this->Print_Error('set_Names(): Error while trying to perform SET NAMES "'.$locale.'" !!!');
  1125.       return(0);
  1126.       }
  1127.     $this->characterset = $charset;
  1128.     return(1);
  1129.     }
  1130.  
  1131.   /**
  1132.    * Method to return the current MySQL setting for the character_set variables.
  1133.    * Note that MySQL returns a list of settings, so this method returns all character_set related
  1134.    * settings as an associative array.
  1135.    * @return array The current settings for the character_set variables.
  1136.    * @since 0.36
  1137.    */
  1138.   function get_CharSet()
  1139.     {
  1140.     $retarr array();
  1141.     $stmt $this->QueryResult("SHOW VARIABLES LIKE 'character_set%'",1);
  1142.     while($d $this->FetchResult($stmt,MYSQL_NUM))
  1143.       {
  1144.       array_push($retarr,$d);
  1145.       }
  1146.     $this->FreeResult($stmt);
  1147.     return($retarr);
  1148.     }
  1149.  
  1150.   /**
  1151.    * Returns the description for a given table.
  1152.    * Array returned has the following fields:
  1153.    * 0 => name of the field
  1154.    * 1 => type of field
  1155.    * 2 => The fieldsize
  1156.    * 3 => Field flags (like auto_increment).
  1157.    * @param string $tname Name of table to describe.
  1158.    * @return array Numerical array with all required table informations.
  1159.    * @since 0.37
  1160.    */
  1161.   function DescTable($tname)
  1162.     {
  1163.     $retarr array();
  1164.     $weopen 0;
  1165.     if(!$this->sock)
  1166.       {
  1167.       $this->Connect();
  1168.       $weopen 1;
  1169.       }
  1170.     if($this->debug)
  1171.       {
  1172.       $this->PrintDebug('DescTable('.$tname.') called - Self-Connect: '.$weopen);
  1173.       }
  1174.     $start $this->getmicrotime();
  1175.     $stmt @mysql_query('SELECT * FROM '.$tname.' LIMIT 1',$this->sock);
  1176.     $fields @mysql_num_fields($stmt);
  1177.     for ($i 0$i $fields$i++)
  1178.       {
  1179.       $retarr[$i][DBOF_MYSQL_COLNAME]   @mysql_field_name($stmt$i);
  1180.       $retarr[$i][DBOF_MYSQL_COLTYPE]   @mysql_field_type($stmt$i);
  1181.       $retarr[$i][DBOF_MYSQL_COLSIZE]   @mysql_field_len($stmt$i);
  1182.       $retarr[$i][DBOF_MYSQL_COLFLAGS]  @mysql_field_flags($stmt$i);
  1183.       }
  1184.     @mysql_free_result($stmt);
  1185.     if($weopen)
  1186.       {
  1187.       $this->Disconnect();
  1188.       }
  1189.     $this->querytime+= ($this->getmicrotime($start);
  1190.     return($retarr);
  1191.     }
  1192.  
  1193.   /**
  1194.    * Function performs an insert statement from a given variable list.
  1195.    * The insert statements will be constructed as NEW Insert style, and aligned to the "max_allowed_packet" boundary.
  1196.    * This can dramatically improve bulk-inserts compared to fire every INSERT statement one by one.
  1197.    * The array passed must be constructed with the keys defined as fieldnames and the values as the corresponding values.
  1198.    * Looks like this:
  1199.    *
  1200.    * - $data[0]['fieldname1'] = 'wert0/1';
  1201.    * - $data[0]['fieldname2'] = 'wert0/2';
  1202.    * - $data[1]['fieldname1'] = 'wert1/2';
  1203.    * - $data[1]['fieldname2'] = 'wert1/2';
  1204.    *
  1205.    * NOTE: Database must be connected!
  1206.    * @param string $table_name Name of table to perform the insert against.
  1207.    * @param array &$fields The associative array
  1208.    * @param string $sql Either "INSERT" or "REPLACE", no other command is allowed here!
  1209.    * @return array A numeric array with [0] => created query count, [1] => Querysize or FALSE in case of an error.
  1210.    * @see examples/new_insert.php
  1211.    */
  1212.   function PerformNewInsert($table_name,&$fields,$sql='INSERT')
  1213.     {
  1214.     $qcount 0;
  1215.     $qsize  0;
  1216.  
  1217.     if(StrToUpper($sql!= 'INSERT' && StrToUpper($sql!= 'REPLACE')
  1218.       {
  1219.       return(FALSE);
  1220.       }
  1221.     $this->checkSock();
  1222.  
  1223.     // First retrieve the max_allowed_packet size:
  1224.     $d $this->Query("SHOW SESSION VARIABLES LIKE 'max_allowed_packet'");
  1225.     $max_allowed_packet intval($d['Value']);
  1226.  
  1227.     // Now start with the initial insert command:
  1228.     $INSERT $sql.' INTO '.$table_name.'(';
  1229.  
  1230.     // Add the fields:
  1231.     foreach($fields as $count => $databreak;
  1232.     foreach($data as $fieldname => $fieldvalue)
  1233.       {
  1234.       $INSERT.=$fieldname.',';
  1235.       }
  1236.     $INSERT substr($INSERT,0,strlen($INSERT)-1).') VALUES ';
  1237.     reset($fields);
  1238.     $query $INSERT;
  1239.     foreach($fields as $count => $data)
  1240.       {
  1241.       $buffer '(';
  1242.       foreach($data as $fieldname => $fieldvalue)
  1243.         {
  1244.         if(is_integer($fieldvalue))
  1245.           {
  1246.           $buffer.=$fieldvalue.',';
  1247.           }
  1248.         else
  1249.           {
  1250.           $buffer.="'".$this->EscapeString($fieldvalue)."',";
  1251.           }
  1252.         }
  1253.       $buffer substr($buffer,0,strlen($buffer)-1).'),';
  1254.       if((strlen($querystrlen($buffer2$max_allowed_packet)
  1255.         {
  1256.         $query.=$buffer;
  1257.         }
  1258.       else
  1259.         {
  1260.         // Flush the current query, then append the new values and start again:
  1261.         $query substr($query,0,strlen($query)-1);
  1262.         $qsize+= strlen($query);
  1263.         $rc $this->Query($query,MYSQL_ASSOC,1);
  1264.         if($rc != 1)
  1265.           {
  1266.           return(FALSE);
  1267.           }
  1268.         $query $INSERT.$buffer;
  1269.         $qcount++;
  1270.         }
  1271.       }
  1272.     // Also add of course the remaining data:
  1273.     if($query != '')
  1274.       {
  1275.       $query substr($query,0,strlen($query)-1);
  1276.       $qsize+= strlen($query);
  1277.       $rc $this->Query($query,MYSQL_ASSOC,1);
  1278.       if($rc != 1)
  1279.         {
  1280.         return(FALSE);
  1281.         }
  1282.       $qcount++;
  1283.       }
  1284.     //printf("QUERIES GENERATED: %d - total size of all queries: %d\n",$qcount,$qsize);
  1285.     return(array($qcount,$qsize));
  1286.     }
  1287.  
  1288.   /**
  1289.    * Returns the number of rows in the result set.
  1290.    * Use this after a SELECT or SHOW etc. command has been executed.
  1291.    * For DML operations like INSERT, UPDATE, DELETE the method AffectedRows() has to be used.
  1292.    * @return integer Number of affected rows.
  1293.    * @since 0.38
  1294.    * @see mysql_num_rows()
  1295.    * @see AffectedRows()
  1296.    */
  1297.   function NumRows()
  1298.     {
  1299.     return($this->num_rows);
  1300.     }
  1301.  
  1302.   // EOF
  1303. ?>

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