我在xampp中使用laravel5.4和php7.2。我试图截断一个临时表,然后从mysql视图插入新数据。代码执行并执行我希望它执行的操作,但它说有一个错误-
sqlstate[hy000]:常规错误(sql:insert into prod\u joins\u temp(date,code,sid,time\u start,time\u end,made,firsts,seconds,p\u break,q\u break,g\u break,prod\u id)选择日期,code,sid,time\u start,time\u end,made,firsts,seconds,p\u break,q\u break,g\u break,prod\u id from prod\u joins)
最初我有以下错误 General error: 1615 Prepared statement needs to be re-prepared
在我的视图中插入两列后:a time_start
以及 time_end
列。
我试图删除这两列,看看这是否是问题所在,但现在我只得到了可怕的一般性错误。
我尝试了这个答案拉威尔:一般错误:1615准备语句需要重新准备。它没有工作,根据评论,这将导致问题验证。
我发现这个答案pdo错误:“sqlstate[hy000]:general error”在更新数据库时,这与我的问题完全相同,但它没有回答我的问题,因为我没有使用 fetchAll()
我也不使用任何变量的任何重复变量。
我试过以下两种方法来实现我的目标。
截断表prod\u joins\u temp
ProdJoinsTemp::truncate();
然后从prod\u joins视图填充表prod\u joins\u temp
DB::select('Insert Into prod_joins_temp (date,code,sid,time_start,time_end,made,firsts,seconds,p_broken,q_broken,g_broken,prod_id) Select date,code,sid,time_start,time_end,made,firsts,seconds,p_broken,q_broken,g_broken,prod_id From prod_joins');
另一种方法给出了完全相同的错误,如下所示
删除表prod\u joins\u temp(如果存在)
\Schema::dropIfExists('prod_joins_temp');
然后从prod\u joins视图创建表prod\u joins\u temp
DB::select('CREATE TABLE prod_joins_temp AS SELECT * FROM prod_joins;');
下面是生成视图的代码
SELECT
`scorecard54`.`production`.`date` AS `date`,
`scorecard54`.`products`.`code` AS `code`,
`scorecard54`.`production`.`sid_production` AS `sid`,
`scorecard54`.`production`.`time_start` AS `time_start`,
`scorecard54`.`production`.`time_end` AS `time_end`,
`scorecard54`.`production`.`made` AS `made`,
`scorecard54`.`qcontrol`.`firsts` AS `firsts`,
`scorecard54`.`qcontrol`.`seconds` AS `seconds`,
`scorecard54`.`production`.`broken_production` AS `p_broken`,
`scorecard54`.`qcontrol`.`broken_qcontrol` AS `q_broken`,
`scorecard54`.`grinding`.`discarded` AS `g_broken`,
`scorecard54`.`products`.`prod_id` AS `prod_id`
FROM
(
(
(
`scorecard54`.`production`
LEFT JOIN `scorecard54`.`products` ON
(
(
`scorecard54`.`production`.`prod_code` = `scorecard54`.`products`.`prod_id`
)
)
)
LEFT JOIN `scorecard54`.`grinding` ON
(
(
`scorecard54`.`production`.`sid_production` = `scorecard54`.`grinding`.`sid_grinding`
)
)
)
LEFT JOIN `scorecard54`.`qcontrol` ON
(
(
`scorecard54`.`grinding`.`tray_id_grinding` = `scorecard54`.`qcontrol`.`tray_id_qcontrol`
)
)
)
WHERE
(
`scorecard54`.`grinding`.`have_qcontrol` = 1
)
下面是从视图中删除并创建表的函数
public function generateTable(Request $request) {
// Drop temp table
\Schema::dropIfExists('prod_joins_temp');
// re create table with the new data
DB::select('CREATE TABLE prod_joins_temp AS SELECT * FROM prod_joins;');
$request->session()->flash('alert-success', 'Success: Reports table regenerated.');
return Redirect::to('/statistics/');
}
我还尝试了截断然后用这个函数重新填充
public function generateTable(Request $request) {
// Drop temp table
ProdJoinsTemp::truncate();
// re generate table with the new data
DB::select('Insert Into prod_joins_temp (date,code,sid,time_start,time_end,made,firsts,seconds,p_broken,q_broken,g_broken,prod_id) Select date,code,sid,time_start,time_end,made,firsts,seconds,p_broken,q_broken,g_broken,prod_id From prod_joins');
$request->session()->flash('alert-success', 'Success: Reports table regenerated.');
return Redirect::to('/statistics/');
}
我做错什么了?是否有某种视图缓存?
1条答案
按热度按时间6l7fqoea1#
我已经通过这个答案修复了这个问题sqlstate[hy000]:一般错误:2053错误发生在laravel
在我使用以下命令更新表之前
我将查询的select部分改为update,一切正常。请看下面
我不知道为什么以前的方法在我向视图中添加字段之前有效,但是现在它要求我使用update而不是select