yii\db\Connection::quoteColumnName PHP Méthode

quoteColumnName() public méthode

If the column name contains prefix, the prefix will also be properly quoted. If the column name is already quoted or contains special characters including '(', '[[' and '{{', then this method will do nothing.
public quoteColumnName ( string $name ) : string
$name string column name
Résultat string the properly quoted column name
    public function quoteColumnName($name)
    {
        return $this->getSchema()->quoteColumnName($name);
    }

Usage Example

Exemple #1
0
 /**
  * @param integer $count
  * @return \Generator
  * @throws Exception
  */
 public function export($count)
 {
     if (!$this->table) {
         throw new Exception("table name is required");
     }
     if (is_null($this->db)) {
         $this->db = \Yii::$app->get($this->db_component);
     }
     $this->table_quoted = $this->db->quoteTableName($this->table);
     $this->truncate();
     $first_row = $this->generator->generate()->current();
     // prepare quoted fileds name list
     $fields = array_map(function ($i) {
         return $this->db->quoteColumnName($i);
     }, array_keys($first_row));
     $fields_str = implode(",", $fields);
     // prepare values section, repeat values block $rows_per_request number
     $rows_per_request = 1;
     if ($this->multirow) {
         $rows_per_request = (int) max(floor($this->placeholder_limit / count($fields)), 1);
     }
     $placeholders = "(" . implode(",", array_fill(1, count($fields), '?')) . ")";
     $value_placeholders = implode(",", array_fill(1, $rows_per_request, $placeholders));
     // finally sql request
     $prepare = $this->db->createCommand("INSERT INTO {$this->table_quoted}({$fields_str}) VALUES {$value_placeholders}");
     // first row of data, lets save it
     $insert_values = $this->array1based($first_row);
     $prepared_rows = 1;
     foreach ($this->generator->generate() as $item) {
         if ($prepared_rows === $rows_per_request) {
             unset($insert_values[0]);
             $prepare->bindValues($insert_values);
             $prepare->execute();
             $count = $count - $rows_per_request;
             if ($count <= 0) {
                 break;
             }
             (yield $count);
             $insert_values = $this->array1based($item);
             $prepared_rows = 1;
         } else {
             $insert_values = array_merge($insert_values, array_values($item));
             $prepared_rows++;
         }
     }
 }
All Usage Examples Of yii\db\Connection::quoteColumnName