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

问题描述 投票:0回答:1

我有大型 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();
    }
}

我收到以下异常:

======================================================================
   The application has thrown an exception!
======================================================================
 Propel\Runtime\Exception\PropelException
 Unable to execute SELECT statement [SELECT user.ID, user.EMAIL, user.PASSWORD, user.PHONE, user.IP, user.PROCESSED, user.WHEN FROM `user` WHERE user.PROCESSED=:p1 LIMIT 100]
----------------------------------------------------------------------


// debug backtrace

======================================================================
   Previous Exception(s):
======================================================================
 PDOException
 SQLSTATE[42000]: Syntax error or access violation: 1461 Can't create more than max_prepared_stmt_count statements (current value: 16382)
----------------------------------------------------------------------

// debug backtrace

显然,原因是:

连接到数据库的应用程序正在准备 sql 语句,执行它们,然后不关闭它们。

如何推动关闭报表?我确实使用 Propel 2: "propel/propel": "2.0.*@dev"

php mysql pdo propel
1个回答
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);
    
© www.soinside.com 2019 - 2024. All rights reserved.