Laravel:一般错误:1615 Prepared statement需要重新准备
问题描述
我在宅基地虚拟机 (vagrant) 中使用最新版本的 laravel (5.1).
I'm using last version of laravel (5.1) in a homestead virtual machine (vagrant).
我将我的项目连接到本地 mariaDB 服务器,其中我有一些表和 2 个 db-view.
I connect my project to a local mariaDB server, in which I have some table and 2 db-view.
由于我仅在 db-view 表上进行了一些选择,因此我随机收到此错误:
Since I made some select only on the db-view tables, I receive back randomly this error:
一般错误:1615 Prepared statement需要重新准备
General error: 1615 Prepared statement needs to be re-prepared
从今天开始,当只在数据库视图上进行选择时,我总是会收到此错误.如果我打开我的 phpMyAdmin 并进行相同的选择,它会返回正确的结果.
From today, I always get this error when made select only on the db views. If I open my phpMyAdmin and make the same select it return the correct result.
我试图打开 php artisan tinker
并选择 db-view 的一条记录,但它返回相同的错误:
I tried to open php artisan tinker
and select one record of the db-view but it return the same error:
我该如何解决这个问题?我读到了 mysqldump 的一个问题(但在我的情况下不是)并增加了 table_definition_cache
的值,但不确定它是否会起作用,我无法修改它们.
How can I fix that?
I read about a problem with mysqldump (but not in my case) and to increase value of table_definition_cache
but it is not sure that it will work and I can't modify them.
这是一种 laravel 的 bug 吗?
Is this a kind of laravel bug?
我怎么知道?
按照要求,我添加了我的模型源代码.源码.php:
As asked, I add my model source code. Source.php:
<小时>
编辑 2:
Edit 2:
如果我在项目中使用 mysqli 执行相同的查询,它会起作用:
If I execute the same query in the project with mysqli it works:
<小时>
编辑 3:2个月后,我还在.同样的错误,没有找到解决方案.我决定在 aritsan tinker 中尝试一个小解决方案,但没有好消息.我报告了我的尝试:
EDIT 3: Afeter 2 month, I'm still there. Same error and no solution found. I decide to try a little solution in aritsan tinker but no good news. I report what I've tried:
首先尝试获取一个表模型:
First try to fetch a table model:
现在尝试获取视图表模型:
Now try to fetch a view table model:
当 contentRepository 在模型 ContentRepository.php 中没有正确的表名设置时:
When contentRepository doesn't have correct table name setup inside the model ContentRepository.php:
在模型 ContentRepository.php 中更改表值:
CHANGE TABLE VALUE INSIDE model ContentRepository.php:
正确时,注意缺少的errorInfo":
显示 db 的表:
尝试正常选择:
尝试未准备的查询:
尝试第二次未准备的查询:
Try second time unprepared query:
试试 PDOStatement::fetchAll():
Try PDOStatement::fetchAll():
尝试第二个 PDOStatement::fetchAll():
Try second PDOStatement::fetchAll():
Try 语句...:
谢谢
推荐答案
好像可以添加
在数据库配置中的 projectName/config/database.php
文件中.会是这样的:
Inside projectName/config/database.php
file in DB configuration. It will be like this:
Laravel 5.1.希望对您有所帮助!
Laravel 5.1. Hope it will help!
我目前在 Laravel 8 上,这个解决方案仍然有效.
I'm currently on Laravel 8 and this solution is still working.
这篇关于Laravel:一般错误:1615 Prepared statement需要重新准备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!