PHPLinq_Adapter
[ class tree: PHPLinq_Adapter ] [ index: PHPLinq_Adapter ] [ all elements ]

Source for file Mysqli.php

Documentation is available at Mysqli.php

  1. <?php
  2. /**
  3.  * PHPLinq
  4.  *
  5.  * Copyright (c) 2008 - 2009 PHPLinq
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPLinq
  22.  * @package    PHPLinq_Adapter
  23.  * @copyright  Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq)
  24.  * @license    http://www.gnu.org/licenses/lgpl.txt    LGPL
  25.  * @version    0.4.0, 2009-01-27
  26.  */
  27.  
  28.  
  29. /** PHPLinq_Adapter_Abstract */
  30. require_once 'PHPLinq/Adapter/Abstract.php';
  31.  
  32.  
  33. /**
  34.  * PHPLinq_Adapter_Mysqli
  35.  *
  36.  * @category   PHPLinq
  37.  * @package    PHPLinq_Adapter
  38.  * @copyright  Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq)
  39.  */
  40.     /**
  41.      * Constructor
  42.      *
  43.      * @param Zend_Db_Adapter_Abstract $adapter 
  44.      */
  45.     public function __construct(Zend_Db_Adapter_Abstract $adapter null{
  46.         return parent::__construct($adapter);
  47.     }
  48.     
  49.     /**
  50.      * Convert operator
  51.      *
  52.      * @param string $operator 
  53.      * @return string 
  54.      */
  55.     public function operator($operator{
  56.         switch ($operator{
  57.             case '=':
  58.             case '!=':
  59.             case '>=':
  60.             case '<=':
  61.             case '>':
  62.             case '<':
  63.             case '+':
  64.             case '-':
  65.             case '*':
  66.             case '/':
  67.             case '%':
  68.                 return $operator;
  69.             case '.':
  70.                 return '||';
  71.         }
  72.     }
  73.     
  74.     /**
  75.      * Return ASCII value of character
  76.      *
  77.      * @param string $string A character
  78.      * @return string 
  79.      */
  80.     public function ord($string{
  81.         return 'ASCII(' $string ')';
  82.     }
  83.     
  84.     /**
  85.      * Return a specific character
  86.      *
  87.      * @param int $string The ascii code
  88.      * @return string 
  89.      */
  90.     public function chr($ascii{
  91.         return 'CHAR(' $string ')';
  92.     }
  93.     
  94.     /**
  95.      * Return part of a string
  96.      *
  97.      * @param string $string 
  98.      * @param int $start 
  99.      * @param int $length 
  100.      * @return string 
  101.      */
  102.     public function substr($string$start$length ''{
  103.         if ($length == ''{
  104.             return 'SUBSTRING(' $string ', ' $start ')';
  105.         }
  106.         
  107.         return 'SUBSTRING(' $string ', ' $start ', ' $length ')';
  108.     }
  109.     
  110.     /**
  111.      * Get string length
  112.      *
  113.      * @param string $string 
  114.      * @return string 
  115.      */
  116.     public function strlen($string{
  117.         return 'CHAR_LENGTH(' $string ')';
  118.     }
  119.     
  120.     /**
  121.      * Count elements in an array, or properties in an object
  122.      *
  123.      * @param mixed $var 
  124.      * @return string 
  125.      */
  126.     public function count($var
  127.         return 'COUNT(' $var ')';
  128.     }
  129.     
  130.     /**
  131.      * Find highest value
  132.      *
  133.      * @param mixed $values 
  134.      * @return string 
  135.      */
  136.     public function max($values
  137.         return 'MAX(' $values ')';
  138.     }
  139.     
  140.     /**
  141.      * Find lowest value
  142.      *
  143.      * @param mixed $values 
  144.      * @return string 
  145.      */
  146.     public function min($values
  147.         return 'MIN(' $values ')';
  148.     }
  149.     
  150.     /**
  151.      * Absolute value
  152.      *
  153.      * @param mixed $number 
  154.      * @return string 
  155.      */
  156.     public function abs($number{
  157.         return 'ABS(' $number ')';
  158.     }
  159.     
  160.     /**
  161.      * Make a string lowercase
  162.      *
  163.      * @param string $str 
  164.      * @return string 
  165.      */
  166.     public function strtolower($str
  167.         return 'LOWER(' $str ')';
  168.     }
  169.     
  170.     /**
  171.      * Make a string uppercase
  172.      *
  173.      * @param string $str 
  174.      * @return string 
  175.      */
  176.     public function strtoupper($str{
  177.         return 'UPPER(' $str ')';
  178.     }
  179.     
  180.     /**
  181.      * Strip whitespace (or other characters) from the beginning of a string
  182.      *
  183.      * @param string $str 
  184.      * @return string 
  185.      */
  186.     public function ltrim($str{
  187.         return 'LTRIM(' $str ')';
  188.     }
  189.     
  190.     /**
  191.      * Generate a random integer
  192.      * 
  193.      * @return string 
  194.      */
  195.     public function rand(
  196.         return 'RAND()';
  197.     }
  198.     
  199.     /**
  200.      * Replace all occurrences of the search string with the replacement string
  201.      *
  202.      * @param mixed $search 
  203.      * @param mixed $replace 
  204.      * @param mixed $subject 
  205.      * @return string 
  206.      */
  207.     public function str_replace($search$replace$subject{
  208.         return 'REPLACE(' $subject ', ' $search  ', ' $replace ')';
  209.     }
  210.     
  211.     /**
  212.      * Rounds a float
  213.      *
  214.      * @param float $val 
  215.      * @param int $precision 
  216.      * @return string 
  217.      */
  218.     public function round($val$precision 0{
  219.         return 'ROUND(' $val ', ' $precision ')';
  220.     }
  221.     
  222.     /**
  223.      * Strip whitespace (or other characters) from the end of a string
  224.      *
  225.      * @param string $str 
  226.      * @return string 
  227.      */
  228.     public function rtrim($str{
  229.         return 'RTRIM(' $str ')';
  230.     }
  231.     
  232.     /**
  233.      * Strip whitespace (or other characters) from the beginning and end of a string
  234.      *
  235.      * @param string $str 
  236.      * @return string 
  237.      */
  238.     public function trim($str{
  239.         return 'TRIM(' $str ')';
  240.     }
  241.     
  242.     /**
  243.      * Find position of first occurrence of a string
  244.      *
  245.      * @param string $haystack 
  246.      * @param mixed $needle 
  247.      * @param int $offset 
  248.      * @return string 
  249.      */
  250.     public function strpos($haystack$needle$offset 0{
  251.         return 'LOCATE(' $needle ', ' $haystack ',  ' $offset ')';
  252.     }
  253.     
  254.     /**
  255.      * Find position of first occurrence of a case-insensitive string
  256.      *
  257.      * @param string $haystack 
  258.      * @param mixed $needle 
  259.      * @param int $offset 
  260.      * @return string 
  261.      */
  262.     public function stripos($haystack$needle$offset 0{
  263.         return $this->strpos$this->strtolower($haystack)$this->strtolower($needle)$offset );
  264.     }
  265.     
  266.     /**
  267.      * Make a string's first character lowercase
  268.      *
  269.      * @param string $str 
  270.      * @return string 
  271.      */
  272.     public function lcfirst($str{
  273.         return 'CONCAT(' $this->strtolower($this->substr($str01)) ', ' $this->substr($str1$this->strlen($str1')';
  274.     }
  275.     
  276.     /**
  277.      * Make a string's first character uppercase
  278.      *
  279.      * @param string $str 
  280.      * @return string 
  281.      */
  282.     public function ucfirst($str{
  283.         return 'CONCAT(' $this->strtoupper($this->substr($str01)) ', ' $this->substr($str1$this->strlen($str1')';
  284.     }
  285.     
  286.     /**
  287.      * Calculate the md5 hash of a string
  288.      *
  289.      * @param string $str 
  290.      * @param boolean $raw_output 
  291.      * @return string 
  292.      */
  293.     public function md5($str$raw_output false{
  294.         return 'MD5(' $str ')';
  295.     }
  296.     
  297.     /**
  298.      * Calculate the sha1 hash of a string
  299.      *
  300.      * @param string $str 
  301.      * @param boolean $raw_output 
  302.      * @return string 
  303.      */
  304.     public function sha1($str$raw_output false{
  305.         return 'SHA1(' $str ')';
  306.     }
  307.     
  308.     /**
  309.      * Calculate the soundex key of a string
  310.      *
  311.      * @param string $str 
  312.      * @return string 
  313.      */
  314.     public function soundex($str{
  315.         return 'SOUNDEX(' $str ')';
  316.     }
  317.     
  318.     /**
  319.      * Quote string with slashes
  320.      *
  321.      * @param string $str 
  322.      * @return string 
  323.      */
  324.     public function addslashes($str{
  325.         return 'QUOTE(' $str ')';
  326.     }
  327.     
  328.     /**
  329.      * Repeat a string
  330.      *
  331.      * @param string $input 
  332.      * @param int $multiplier 
  333.      * @return string 
  334.      */
  335.     public function str_repeat($input$multiplier{
  336.         return 'REPEAT(' $input ', ' $multiplier ')';
  337.     }
  338. }

Documentation generated on Tue, 27 Jan 2009 08:29:36 +0100 by phpDocumentor 1.4.1