1615准备的语句需要重新准备

1615准备的语句需要重新准备

本文介绍了常规错误:1615准备的语句需要重新准备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次尝试将中等大小的JSON对象同步到我的数据库时,我就一直遇到这个问题,因此我们可以对其执行一些报告.通过调查可能导致该问题的原因,我遇到了这些问题上的这些链接.

I have been running into this issue every time I try and sync a medium size JSON object to my database so we can perform some reporting on it. From looking into what can cause it I have come across these links on the matter.

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

两个似乎都指向table_definition_cache的方向.但是,这表示问题是由于同时在服务器上发生mysqldump引起的.我可以向您保证,事实并非如此.进一步,我缩小了查询范围,一次只插入一个对象.

Both seem to point me in the direction of table_definition_cache. However this is saying the issue is due to a mysqldump happening on the server at the same time. I can assure you that this is not the case. Further I have slimmed down the query to only insert one object at a time.

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();
}

这是引发错误时正在运行的代码.通常以...的形式出现.

This is the code that is running when the error is thrown. Which normally comes in the form of.

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应用程序中似乎也很常见.

If anyone can point me in the right direction I would be very grateful. I am more curious about what is actually triggering the error then finding the cause of this specific issue. It also seems to be somewhat common in laravel application when using the ORM.

推荐答案

虽然mysqldump是常见的原因,但并非唯一原因.

While mysqldump is the commonly reported cause for this it is not the only one.

就我而言,在任何数据库上运行artisan:migrate也会对同一服务器上的不同数据库触发此错误.

In my case running artisan:migrate on any database will also trigger this error for different databases on the same server.

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

http://bugs.mysql.com/bug.php?id=42041Mentions table locks/flush which would be called in a mysqldump so worth checking if you have any migrations, locks or flushes happening simultaneously.

尝试将准备切换为仿真失败.

Failing that try switching the prepares to emulated.

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

这篇关于常规错误:1615准备的语句需要重新准备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 11:56