以下是我的询问:
\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) 'yii\db\Exception' with message '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 'FROM `schoolwall-50` WHERE ID=149
' at line 1
The SQL being executed was: INSERT INTO `schoolwall-10` SELECT FROM `schoolwall-50` WHERE ID=149'
;
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->convertException
(Object(PDOException), 'INSERT INTO `sc...')
#1 /var/www/html/OroolaGIT/OroolaPhase1/frontend/models/Wall.php(1317): yii\db\Command->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->saveShareWithCommunities()
#5 [internal function]: frontend\controllers\WallController->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-
>runWithParams(Array)
#8 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller-
>runAction('modal-share-pop...', Array)
#9 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module-
>runAction('wall/modal-shar...', Array)
#10 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application-
>handleRequest(Object(yii\web\Request))
#11 /var/www/html/OroolaGIT/OroolaPhase1/frontend/web/index.php(18): yii\base\Application->run()
#12 {main}</pre>
为什么&amp;#039附加到查询中?任何人都可以帮忙。
答案 0 :(得分:0)
缺少*尝试添加
\Yii::$app->db->createCommand("INSERT INTO `schoolwall-10`
SELECT * FROM `schoolwall-50` WHERE ID= 149 ;")->execute();