Propel ORM:PDOException“无法创建超过max_prepared_stmt_count语句”

时间:2014-09-09 09:45:32

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

我收到以下异常:

=============================================== =======================

该应用程序抛出异常!

行走\运行\异常\ PropelException

无法执行SELECT语句[SELECT user.ID,user.EMAIL,user.PASSWORD,user.PHONE,user.IP,user.PROCESSED,user.WHEN FROM user WHERE user.PROCESSED =:p1限制100]

// debug backtrace

=============================================== =======================

以前的例外:

PDOException

SQLSTATE [42000]:语法错误或访问冲突:1461无法创建超过max_prepared_stmt_count的语句(当前值:16382)

// debug backtrace

显然,原因是:

  

An application con正在准备数据库正在准备sql   语句,执行它们,然后不关闭它们。

如何让Propel结束发言?我确实使用了Propel 2:"推进/推进":" 2.0。* @ dev"

1 个答案:

答案 0 :(得分:0)

解决:

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