createCommand'附加到查询生成数据库异常

时间:2016-05-12 12:45:26

标签: exception yii2

以下是我的询问:

\Yii::$app->db->createCommand("INSERT INTO `schoolwall-10` SELECT FROM `schoolwall-50` WHERE ID=149")->execute();

使用以下查询给出了异常(数据库异常)

INSERT INTO `schoolwall-10` SELECT FROM `schoolwall-50` WHERE ID=149' 

更新

<pre>Exception (Database Exception) &#039;yii\db\Exception&#039; with message &#039;SQLSTATE[42000]:
 Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds
 to your MySQL server version for the right syntax to use near &#039;FROM `schoolwall-50` WHERE ID=149
&#039; at line 1
The SQL being executed was: INSERT INTO `schoolwall-10` SELECT FROM `schoolwall-50` WHERE ID=149&#039
; 

in /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/db/Schema.php:615

Stack trace:
#0 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/db/Command.php(789): yii\db\Schema-&gt;convertException
(Object(PDOException), &#039;INSERT INTO `sc...&#039;)
#1 /var/www/html/OroolaGIT/OroolaPhase1/frontend/models/Wall.php(1317): yii\db\Command-&gt;execute()

#2 /var/www/html/OroolaGIT/OroolaPhase1/frontend/models/Wall.php(1245): frontend\models\Wall::saveShareWithCommunities
(Array, Object(frontend\models\SharePopupModal))
#3 /var/www/html/OroolaGIT/OroolaPhase1/frontend/models/SharePopupModal.php(58): frontend\models\Wall
::shareWithPrimarySchoolCommunities(Object(frontend\models\SharePopupModal))
#4 /var/www/html/OroolaGIT/OroolaPhase1/frontend/controllers/WallController.php(3726): frontend\models
\SharePopupModal-&gt;saveShareWithCommunities()
#5 [internal function]: frontend\controllers\WallController-&gt;actionModalSharePopupSubmit()
#6 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array
(Array, Array)
#7 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction-
&gt;runWithParams(Array)
#8 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller-
&gt;runAction(&#039;modal-share-pop...&#039;, Array)
#9 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module-
&gt;runAction(&#039;wall/modal-shar...&#039;, Array)
#10 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application-
&gt;handleRequest(Object(yii\web\Request))
#11 /var/www/html/OroolaGIT/OroolaPhase1/frontend/web/index.php(18): yii\base\Application-&gt;run()
#12 {main}</pre>

为什么&amp;#039附加到查询中?任何人都可以帮忙。

1 个答案:

答案 0 :(得分:0)

缺少*尝试添加

 \Yii::$app->db->createCommand("INSERT INTO `schoolwall-10` 
     SELECT * FROM `schoolwall-50` WHERE ID= 149 ;")->execute();