1、在\framework\db\CDbCommand.php新加insertSeveral() 方法
第二步:执行添加
<span style="font-size:14px;">/**
* @param string $table the table that new rows will be inserted into.
* @param array $columns the column data (name=>value) to be inserted into the table.
* @return integer number of rows affected by the execution.
*/
public function insertSeveral($table, $array_columns)
{
$sql = '';
$params = array();
$i = 0;
foreach ($array_columns as $columns) {
$names = array();
$placeholders = array();
foreach ($columns as $name => $value) {
if (!$i) {
$names[] = $this->_connection->quoteColumnName($name);
}
if ($value instanceof CDbExpression) {
$placeholders[] = $value->expression;
foreach ($value->params as $n => $v)
$params[$n] = $v;
} else {
$placeholders[] = ':' . $name . $i;
$params[':' . $name . $i] = $value;
}
}
if (!$i) {
$sql = 'INSERT INTO ' . $this->_connection->quoteTableName($table)
. ' (' . implode(', ', $names) . ') VALUES ('
. implode(', ', $placeholders) . ')';
} else {
$sql .= ',(' . implode(', ', $placeholders) . ')';
}
$i++;
}
return $this->setText($sql)->execute($params);
}</span>
第二步:执行添加
<span style="font-size:14px;">$school = new Schoolattr();
$postList = $school->attributes = $_POST['Schoolattr'];
$countries_type= $postList['countries_type'];
$nameList = explode("\n", $postList['name']);
foreach($nameList as $key => $value){
$schooldata['name'] = $value;
$schooldata['pid'] = 0;
$schooldata['countries_type'] = $countries_type;
$schooldata['level'] =1;
$command = Yii::app()->db->createCommand();
$command->insert('un_school_attr', $schooldata);
} </span>