Pop\Db\Sql::quote PHP Метод

quote() публичный Метод

Quote the value with single quotes
public quote ( string $value ) : string
$value string
Результат string
    public function quote($value)
    {
        if ($value != '?' && substr($value, 0, 1) != ':' && preg_match('/^\\$\\d*\\d$/', $value) == 0 && !is_int($value) && !is_float($value)) {
            $value = "'" . $this->db->adapter()->escape($value) . "'";
        }
        return $value;
    }

Usage Example

Пример #1
0
 /**
  * Predicate render method
  *
  * @param  int $count
  * @return string
  */
 public function render($count = 1)
 {
     $where = null;
     // Build any nested predicates
     //if (null !== $this->nested) {
     //    $where = '(' . $this->nested . ')';
     //}
     if (count($this->nested) > 0) {
         $where = '(' . implode(') AND (', $this->nested) . ')';
     }
     // Loop through and format the predicates
     if (count($this->predicates) > 0) {
         if (null !== $where) {
             $where .= ' ' . $this->predicates[0]['combine'] . ' ';
         }
         $paramCount = $count;
         $dbType = $this->sql->getDbType();
         foreach ($this->predicates as $key => $predicate) {
             $format = $predicate['format'];
             $curWhere = '(';
             for ($i = 0; $i < count($predicate['values']); $i++) {
                 if ($i == 0) {
                     $format = str_replace('%1', $this->sql->quoteId($predicate['values'][$i]), $format);
                 } else {
                     if (is_array($predicate['values'][$i])) {
                         $vals = $predicate['values'][$i];
                         foreach ($vals as $k => $v) {
                             $predValue = strpos($predicate['values'][0], '.') !== false ? substr($predicate['values'][0], strpos($predicate['values'][0], '.') + 1) : $predicate['values'][0];
                             // Check for named parameters
                             if (':' . $predValue == substr($v, 0, strlen(':' . $predValue)) && $dbType !== \Pop\Db\Sql::SQLITE && $dbType !== \Pop\Db\Sql::ORACLE) {
                                 if ($dbType == \Pop\Db\Sql::MYSQL || $dbType == \Pop\Db\Sql::SQLSRV) {
                                     $v = '?';
                                 } else {
                                     if ($dbType == \Pop\Db\Sql::PGSQL && !$this->sql->getDb()->isPdo()) {
                                         $v = '$' . $paramCount;
                                         $paramCount++;
                                     }
                                 }
                             }
                             $vals[$k] = null === $v ? 'NULL' : $this->sql->quote($v);
                         }
                         $format = str_replace('%' . ($i + 1), implode(', ', $vals), $format);
                     } else {
                         if ($predicate['values'][$i] instanceof \Pop\Db\Sql) {
                             $val = (string) $predicate['values'][$i];
                         } else {
                             $val = null === $predicate['values'][$i] ? 'NULL' : $this->sql->quote($predicate['values'][$i]);
                         }
                         $predValue = strpos($predicate['values'][0], '.') !== false ? substr($predicate['values'][0], strpos($predicate['values'][0], '.') + 1) : $predicate['values'][0];
                         // Check for named parameters
                         if (':' . $predValue == substr($val, 0, strlen(':' . $predValue)) && $dbType !== \Pop\Db\Sql::SQLITE && $dbType !== \Pop\Db\Sql::ORACLE) {
                             if ($dbType == \Pop\Db\Sql::MYSQL || $dbType == \Pop\Db\Sql::SQLSRV) {
                                 $val = '?';
                             } else {
                                 if ($dbType == \Pop\Db\Sql::PGSQL && !$this->sql->getDb()->isPdo()) {
                                     $val = '$' . $paramCount;
                                     $paramCount++;
                                 }
                             }
                         }
                         $format = str_replace('%' . ($i + 1), $val, $format);
                     }
                 }
             }
             $curWhere .= $format . ')';
             if ($key == 0) {
                 $where .= $curWhere;
             } else {
                 $where .= ' ' . $predicate['combine'] . ' ' . $curWhere;
             }
         }
     }
     return $where;
 }
All Usage Examples Of Pop\Db\Sql::quote