php - 推进 ORM : PDOException "Can' t create more than max_prepared_stmt_count statements"

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

我收到以下异常:

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

应用程序抛出异常!

Propel\Runtime\Exception\PropelException

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

//调试回溯

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

之前的异常:

PDO异常

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

//调试回溯

显然,原因是:

An application connecting to the database was preparing sql statements, executing them, then not closing them.

如何让 Propel 关闭语句?我确实使用 Propel 2: "propel/propel": "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);

关于php - 推进 ORM : PDOException "Can' t create more than max_prepared_stmt_count statements",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25741447/

相关文章:

php - 仅显示 laravel 中文本中的字母数

php - 使用 PHP Redis 客户端,在应用程序的每个 PHP 脚本中创建新的 $connection 对象,或者创建一个 GLOBAL $connection 对象?

php - 从谷歌搜索中删除并保护/管理/

Mysql IN - 所有值都是强制性的,而不是 'OR'

mysql - 使用 order by 和 limit 从多个表中删除

php - 如何使用 Netbeans 调试 Symfony3?

php - 这是将表单数据插入 MySQL 数据库的安全方法吗?

php - 使用 PHP 数组将 null 插入 MySQL。 PDO 准备好的报表

php - 警告:PDOStatement::bindValue():SQLSTATE[HY093]:参数编号无效:列/参数基于 1

mysql - 如何删除使用守护程序创建的 sleep mysql 连接