<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>运达&#039;s  blog &#187; 批量插入</title>
	<atom:link href="https://www.yunda51.com/?feed=rss2&#038;tag=%E6%89%B9%E9%87%8F%E6%8F%92%E5%85%A5" rel="self" type="application/rss+xml" />
	<link>https://www.yunda51.com</link>
	<description>运达的博客</description>
	<lastBuildDate>Wed, 12 Nov 2025 07:58:26 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.19</generator>
	<item>
		<title>Yii2.0 批量插入数据</title>
		<link>https://www.yunda51.com/?p=1462</link>
		<comments>https://www.yunda51.com/?p=1462#comments</comments>
		<pubDate>Wed, 24 Dec 2014 06:50:17 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[php技术]]></category>
		<category><![CDATA[Yii]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[yii]]></category>
		<category><![CDATA[批量插入]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1462</guid>
		<description><![CDATA[最近在批量插入数据的时候一直插入数据出错，经过查手册以及度娘，总结出两种方法： 第一种方法： $model =<a href="https://www.yunda51.com/?p=1462" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>最近在批量插入数据的时候一直插入数据出错，经过查手册以及度娘，总结出两种方法：<br />
<strong>第一种方法：</strong></p>
<pre class="wp-code-highlight prettyprint">
$model = new User();
foreach($data as $attributes)
{
     $_model = clone $model;
     $_model-&gt;setAttributes($attributes);
     $_model-&gt;save();
}
</pre>
<p><strong>第二种方法 </strong></p>
<pre class="wp-code-highlight prettyprint">
$model = new User();
foreach($data as $attributes)
{
      $model-&gt;isNewRecord = true;
      $model-&gt;setAttributes($attributes);
      $model-&gt;save() &amp;&amp; $model-&gt;id=0;
}
</pre>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a>  原文地址：<a href="http://www.yunda51.com/1462.html">http://www.yunda51.com/1462.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1462</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
