本文整理汇总了PHP中yii\db\Connection::quoteColumnName方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::quoteColumnName方法的具体用法?PHP Connection::quoteColumnName怎么用?PHP Connection::quoteColumnName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\Connection
的用法示例。
在下文中一共展示了Connection::quoteColumnName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export
/**
* @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++;
}
}
}
示例2: quoteIdentifier
public function quoteIdentifier($str)
{
return $this->connection->quoteColumnName($str);
}