Source for file OCSP_CURSOR_mySQL.phpclass

Documentation is available at OCSP_CURSOR_mySQL.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_CURSOR_mySQL.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms
  7.   * @category   mysql
  8.   *
  9.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   ***/
  13.  
  14.     require_once dirname(__FILE__)."/OCSP_CURSOR.phpclass"// <pk-06-07-26 />
  15.  
  16. /**
  17.   * handels  mySQL database cursor
  18.   *
  19.   * @project    Open CSP-Management
  20.   * @package    dbms
  21.   * @category   mysql
  22.   *
  23.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  24.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  25.   *
  26.   *
  27.   * @todo       currently most function only work with select rights for public
  28.   *              to any table if different db users are used table rights
  29.   *              has to be set manualy
  30.   *
  31.   * @version pk-06-07-26 parent object DB_CURSOR added
  32.   * @version pk-07-06-15 renamed from mySQL_CURSOR to OCSP_CURSOR_mySQL
  33.   *
  34.   ***/
  35. class OCSP_CURSOR_mySQL extends OCSP_CURSOR {
  36.     /**
  37.       * @var mysqlcursor $myCursor 
  38.       ***/
  39.     var $myCursor=FALSE;
  40.     /**
  41.       * @var mysqlconection $myConnId 
  42.       ***/
  43.     var $myConnId=FALSE;
  44.     /**
  45.       * @var bool $bufferd use mysql_query instead of mysql_unbuffered_query
  46.       ***/
  47.     var $buffered=TRUE;
  48.  
  49.     /**
  50.       * calls mysql_query or mysql_unbufferd_query to get a resultset
  51.       *
  52.       * @param mysqlconection  $aConnId 
  53.       * @param string          $aQuery 
  54.       * @param bool            $autoClose  close cursor ofter the last row fetch
  55.       * @param bool            $useBuffer  use mysql_query ?
  56.       * @param debug           since pk-05-01-12
  57.       *
  58.       * @return bool            if we get a valid mySQL cursor
  59.       *
  60.       ***/
  61.     function OCSP_CURSOR_mySQL($aConnId,$aQuery,$autoClose=TRUE,$useBuffer=TRUE,$debug=FALSE{
  62.         if ($debugecho "<p><b>OCSP_CURSOR_mySQL::OCSP_CURSOR_mySQL(... $aQuery ,\$autoClose=$autoClose, ...)</b> (".get_class($this).")</p>";
  63.         if ((empty($aQuery))) {
  64.             return FALSE;
  65.         }
  66.  
  67.         if (!$aConnId{
  68.            $ERR="NO_CONNECTION";
  69.            include $GLOBALS['PROJECT']['PHPINCPAHT']."io/errors.phpinc";
  70.            die();
  71.         }
  72.  
  73.         $this->myQuery       =$aQuery;
  74.         $this->myConnId      =$aConnId;
  75.         $this->myAutoClose   =$autoClose;
  76.         $this->rowNr         =0;
  77.         $this->buffered      =$useBuffer;
  78.  
  79.         if ($useBuffer)
  80.            return ($this->myCursor=@mysql_query($this->myQuery,$this->myConnId));
  81.         else
  82.            return ($this->myCursor=@mysql_unbuffered_query($this->myQuery,$this->myConnId));
  83.  
  84.     }
  85.  
  86.     ##############################################
  87.     /**
  88.       * @param int $pos 
  89.       * @param boolean $debug 
  90.       *
  91.       * @return mixed (array) on success boolean on failure
  92.       *
  93.       */
  94.     function fetchArrayNum($pos=-1,$debug=FALSE{
  95.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CURSOR_mySQL::fetchArrayNum()");
  96.         if ($this->myCursor
  97.         {
  98.             if (!($arr_ret=mysql_fetch_array($this->myCursor))) 
  99.             {
  100.                 if ($this->myAutoClose)
  101.                 {
  102.                    $this->free();
  103.                 }
  104.                 return False;
  105.             else {
  106.                 $this->rowNr++;
  107.                 
  108.                 if (OCSP_CONF::getInstance()->getValue('OUTPUT_ENCODING_CHECK'&& ($str_encoding OCSP_CONF::getInstance()->getValue('OUTPUT_ENCODING')))
  109.                 {
  110.                     foreach($arr_ret as $str_key => $mix_val)
  111.                     {
  112.                         if (!empty($mix_val))
  113.                         {
  114.                             switch($str_encoding)
  115.                             {
  116.                                 case "UTF-8":
  117.                                     if (!OCSP_OBJ::isMultiByteStr($mix_val))
  118.                                     {
  119.                                         $arr_ret[$str_keyutf8_encode($mix_val);                                        
  120.                                     }
  121.                                     break;
  122.                             }              
  123.                         }
  124.                     }
  125.                 }                
  126.                 
  127.                 if ($pos > -1)   return $arr_ret[$pos];
  128.                 else             return $arr_ret;
  129.             }
  130.         else {
  131.             if ($debugocsp_logError(__FILE__,__LINE__,"no cursor",E_WARNING);
  132.             return FALSE;
  133.         }
  134.     }
  135.  
  136.     ##############################################
  137.  
  138.     /**
  139.       * returns an array of a database row
  140.       *
  141.       * @param boolean $ucase make column names uppercase
  142.       * @param boolean $debug 
  143.       *
  144.       * @return array 
  145.       *
  146.       * @global $OCSP_CONF 
  147.       *
  148.       * @version pk-07-08-28
  149.       *
  150.       */
  151.     function fetchArrayFld($ucase=FALSE)
  152.     {        
  153.         if ($this->myCursor)
  154.         {
  155.             if (!($arr_row=@mysql_fetch_assoc($this->myCursor)))
  156.             {
  157.                 if ($this->myAutoClose$this->free();
  158.                 return FALSE;
  159.             else {
  160.                 $this->rowNr++;
  161.                 if ($ucase || OCSP_CONF::getInstance()->getValue('OUTPUT_ENCODING_CHECK'))
  162.                 {
  163.                     $arr_ret=array();
  164.                     if (OCSP_CONF::getInstance()->getValue('OUTPUT_ENCODING_CHECK'))
  165.                     {
  166.                         $str_encoding OCSP_CONF::getInstance()->getValue('OUTPUT_ENCODING');
  167.                     else {
  168.                         $str_encoding "";
  169.                     }
  170.                     
  171.                     foreach($arr_row as $key => $val{
  172.                         if ($ucase$key=strtoupper($key);
  173.                         
  174.                         if (!empty($val&& !empty($str_encoding))
  175.                         {
  176.                             switch($str_encoding)
  177.                             {
  178.                                 case "UTF-8":
  179.                                     if (!OCSP_OBJ::isMultiByteStr($val))
  180.                                     {
  181.                                         $val utf8_encode($val);                                        
  182.                                     }
  183.                                     break;
  184.                             }
  185.                         }                        
  186.                         $arr_ret[$key]=$val;
  187.                     }
  188.                     return $arr_ret;
  189.                 else {
  190.                     return $arr_row;
  191.                 }
  192.             }
  193.         else {
  194.             return FALSE;
  195.         }
  196.     }
  197.  
  198.     ##############################################
  199.     function fetchArray({
  200.         if ($this->myCursor
  201.         {
  202.             $arr_ret=@mysql_fetch_array($this->myCursor);
  203.             if (!$arr_ret
  204.             {
  205.                 if ($this->myAutoClose$this->free();
  206.                 return False;
  207.             else {
  208.                 $this->rowNr++;
  209.                 if (OCSP_CONF::getInstance()->getValue('OUTPUT_ENCODING_CHECK'&& ($str_encoding OCSP_CONF::getInstance()->getValue('OUTPUT_ENCODING')))
  210.                 {
  211.                     foreach($arr_ret as $str_key => $mix_val)
  212.                     {
  213.                         if (!empty($mix_val))
  214.                         {
  215.                             switch($str_encoding)
  216.                             {
  217.                                 case "UTF-8":
  218.                                     if (!OCSP_OBJ::isMultiByteStr($mix_val))
  219.                                     {
  220.                                         $arr_ret[$str_keyutf8_encode($mix_val);                                        
  221.                                     }
  222.                                     break;
  223.                             }              
  224.                         }
  225.                     }
  226.                 }
  227.                 
  228.                 return $arr_ret;
  229.             }
  230.         else {
  231.             return False;
  232.         }
  233.     }
  234.  
  235.  
  236.     /**
  237.       * free the cursor with @mysql_free_result
  238.       **/
  239.  
  240.     function free({
  241.         if ($this->myCursor{
  242.            @mysql_free_result($this->myCursor);
  243.         }
  244.         $this->myCursor=FALSE;
  245.     }
  246.  
  247.     ##############################################
  248.     function numOfRows({
  249.         if ($this->myCursor{
  250.            if ($this->buffered{
  251.               return @mysql_num_rows($this->myCursor);
  252.            else {
  253.               return $this->rowNr * (-1);
  254.            }
  255.         else {
  256.             return $this->rowNr * (-1);
  257.         }
  258.     }
  259. }
  260. ?>

Documentation generated on Thu, 08 Jan 2009 17:45:22 +0100 by phpDocumentor 1.4.0a2