gpt4 book ai didi

mysql - 一般错误 : 1615 Prepared statement needs to be re-prepared

转载 作者:IT老高 更新时间:2023-10-29 00:12:14 29 4
gpt4 key购买 nike

每次我尝试将中等大小的 JSON 对象同步到我的数据库时都会遇到这个问题,以便我们可以对其执行一些报告。通过调查可能导致它的原因,我发现了有关此事的这些链接。

http://blog.corrlabs.com/2013/04/mysql-prepared-statement-needs-to-be-re.html http://bugs.mysql.com/bug.php?id=42041

两者似乎都将我指向 table_definition_cache 的方向。然而,这是说问题是由于服务器上同时发生了 mysqldump。我可以向你保证,情况并非如此。此外,我还精简了查询,一次只插入一个对象。

public function fire($job, $data) 
{
foreach (unserialize($data['message']) as $org)
{
// Ignore ID 33421 this will time out.
// It contains all users in the system.
if($org->id != 33421) {
$organization = new Organization();
$organization->orgsync_id = $org->id;
$organization->short_name = $org->short_name;
$organization->long_name = $org->long_name;
$organization->category = $org->category->name;
$organization->save();

$org_groups = $this->getGroupsInOrganization($org->id);
if (!is_int($org_groups))
{
foreach ($org_groups as $group)
{
foreach($group->account_ids as $account_id)
{
$student = Student::where('orgsync_id', '=', $account_id)->first();
if (is_object($student))
{
$student->organizations()->attach($organization->id, array('is_officer' => ($group->name == 'Officers')));
}
}
}
}
}
}

$job->delete();
}

这是抛出错误时正在运行的代码。通常以以下形式出现。

SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (SQL: insert into `organization_student` (`is_officer`, `organization_id`, `student_id`) values (0, 284, 26))

然后此错误重复 3 次。

SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (SQL: insert into `organizations` (`orgsync_id`, `short_name`, `long_name`, `category`, `updated_at`, `created_at`) values (24291, SA, Society of American, Professional, 2014-09-15 16:26:01, 2014-09-15 16:26:01))

如果有人能指出我正确的方向,我将不胜感激。我对实际触发错误的原因更加好奇,然后找到了这个特定问题的原因。在使用 ORM 时,它在 laravel 应用程序中似乎也很常见。

最佳答案

虽然 mysqldump 是导致此问题的常见原因,但它并不是唯一的原因。

在我的例子中,在任何数据库上运行 artisan:migrate 也会为同一服务器上的不同数据库触发此错误。

http://bugs.mysql.com/bug.php?id=42041提到将在 mysqldump 中调用的表锁定/刷新,因此值得检查您是否同时发生任何迁移、锁定或刷新。

尝试将准备切换为模拟失败。

'options'   => [
\PDO::ATTR_EMULATE_PREPARES => true
]

关于mysql - 一般错误 : 1615 Prepared statement needs to be re-prepared,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25873883/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com