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

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

Quote the value with the quoted identifier
public quoteId ( string $id ) : string
$id string
Результат string
    public function quoteId($id)
    {
        $quotedId = null;
        $startQuote = null;
        $endQuote = null;
        switch ($this->quoteIdType) {
            case self::BACKTICK:
                $startQuote = '`';
                $endQuote = '`';
                break;
            case self::BRACKET:
                $startQuote = '[';
                $endQuote = ']';
                break;
            case self::DOUBLE_QUOTE:
                $startQuote = '"';
                $endQuote = '"';
                break;
        }
        if (strpos($id, '.') !== false) {
            $idAry = explode('.', $id);
            foreach ($idAry as $key => $value) {
                $idAry[$key] = $startQuote . $value . $endQuote;
            }
            $quotedId = implode('.', $idAry);
        } else {
            $quotedId = $startQuote . $id . $endQuote;
        }
        return $quotedId;
    }

Usage Example

Пример #1
0
 /**
  * Set the ORDER BY value
  *
  * @param mixed  $by
  * @param string $order
  * @return AbstractSql
  */
 public function orderBy($by, $order = 'ASC')
 {
     $byColumns = null;
     if (is_array($by)) {
         $quotedAry = [];
         foreach ($by as $value) {
             $quotedAry[] = $this->sql->quoteId(trim($value));
         }
         $byColumns = implode(', ', $quotedAry);
     } else {
         if (strpos($by, ',') !== false) {
             $ary = explode(',', $by);
             $quotedAry = [];
             foreach ($ary as $value) {
                 $quotedAry[] = $this->sql->quoteId(trim($value));
             }
             $byColumns = implode(', ', $quotedAry);
         } else {
             $byColumns = $this->sql->quoteId(trim($by));
         }
     }
     $this->orderBy .= (null !== $this->orderBy ? ', ' : '') . $byColumns;
     $order = strtoupper($order);
     if (strpos($order, 'RAND') !== false) {
         $this->orderBy = $this->sql->getDbType() == \Pop\Db\Sql::SQLITE ? ' RANDOM()' : ' RAND()';
     } else {
         if ($order == 'ASC' || $order == 'DESC') {
             $this->orderBy .= ' ' . $order;
         }
     }
     return $this;
 }
All Usage Examples Of Pop\Db\Sql::quoteId