Php 推进ORM:PDOException“创建的语句不能超过max_prepared_stmt_count”
我有很大的MySQL数据库。我想一次提取100行,直到处理完所有数据库Php 推进ORM:PDOException“创建的语句不能超过max_prepared_stmt_count”,php,mysql,pdo,propel,Php,Mysql,Pdo,Propel,我有很大的MySQL数据库。我想一次提取100行,直到处理完所有数据库 protected function doEcho($msg){ static $time, $start; if (!$start) $start = time(); if (time() - $time > 0) { echo $msg . "\n\n"; $time = time(); } } // ZF2 action public funct
protected function doEcho($msg){
static $time, $start;
if (!$start) $start = time();
if (time() - $time > 0) {
echo $msg . "\n\n";
$time = time();
}
}
// ZF2 action
public function stuffAction() {
$request = $this->getRequest();
if (!$request instanceof ConsoleRequest){
throw new \RuntimeException('You can only use this action from a console!');
}
// Propel ORM generated Model UserQuery
$q = \UserQuery::create()->limit(100)->filterByProcessed(0);
$users = $q->find();
while ($users->count() ) {
foreach ($users as $user) {
$id = $user->getId();
$email = $user->getEmail();
$password = $user->getPassword();
$this->doEcho("$id - $email - $password");
// do stuff and set processed to 1
}
$q = \UserQuery::create()->limit(100)->filterByProcessed(0);
$users = $q->find();
}
}
我遇到以下异常:
======================================================================
应用程序引发了一个异常!
推进\运行时\异常\属性异常
无法执行SELECT语句[选择user.ID、user.EMAIL、user.PASSWORD、user.PHONE、user.IP、user.PROCESSED、user.WHEN FROM user WHERE user.PROCESSED=:p1 LIMIT 100]
//调试回溯
======================================================================
以前的例外情况:
PDO例外
SQLSTATE[42000]:语法错误或访问冲突:1461不能创建超过max_prepared_stmt_count语句当前值:16382
//调试回溯
很明显,原因是:
连接到数据库正在准备sql
语句,执行它们,然后不关闭它们
我该如何做结束陈述?我确实使用了推进2:spreep/spreep:2.0.@dev解决了:
use Propel\Runtime\Propel;
use Propel\Runtime\Connection\ConnectionWrapper;
// ...
Propel::getServiceContainer()
// connection_name - connection from propel config
->getReadConnection('connection_name')
->setAttribute(ConnectionWrapper::PROPEL_ATTR_CACHE_PREPARES, true);
我不是一个推进用户,所以我写这篇文章是作为一个评论。您是否可以将\UserQuery::create存储到一个成员,例如$this->q=\UserQuery::create,然后使用$this->q->setLimit100->setOffset100更改限制和偏移量,从而在数据集中移动,而不是不断创建新语句?它可能不起作用,但在得到正确答案之前——你可以试一试。事实上,这是我在面对这个问题时第一次尝试。但并没有什么变化:在工作21秒后,脚本死掉,抛出了提到的异常。我通过使用旧的不推荐使用的mysql下划线函数来修复它,为什么不直接使用PDO来修复它呢?与mysql_*相比,您将得到更少的代码,并且您将使用受支持的接口而不是过时的接口。我对它更熟悉。我需要尽快解决这个问题。