示例#1
0
 public function testQuote_Array()
 {
     $this->assertEquals('(1, TRUE, "abc", DEFAULT)', QuerySplitter::quote(array(1, true, "abc", null), 'DEFAULT'));
 }
示例#2
0
 /**
  * Quote a value so it can be savely used in a query.
  * 
  * @param mixed  $value
  * @param string $empty  Return $empty if $value is null
  * @return string
  */
 public static function quote($value, $empty = 'NULL')
 {
     return QuerySplitter::quote($value, $empty);
 }
示例#3
0
 /**
  * Insert parameters into SQL query.
  * Don't mix unnamed ('?') and named (':key') placeholders.
  *
  * @param mixed $statement  Query string or Query::Statement object
  * @param array $params     Parameters to insert into statement on placeholders
  * @return mixed
  */
 public static function bind($statement, $params)
 {
     if (empty($params)) {
         return $statement;
     }
     $fn = function ($match) use(&$params) {
         if (!empty($match[2]) && !empty($params)) {
             $value = array_shift($params);
         } elseif (!empty($match[3]) && array_key_exists($match[3], $params)) {
             $value = $params[$match[3]];
         } else {
             return $match[0];
         }
         if (isset($value) && ($match[1] || $match[4])) {
             $value = $match[1] . $value . $match[4];
         }
         return QuerySplitter::quote($value);
     };
     return preg_replace_callback('/`[^`]*+`|"(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\'|(%?)(?:(\\?)|:(\\w++))(%?)/', $fn, $statement);
 }