php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69569 cpu usage
Submitted: 2015-05-04 12:00 UTC Modified: 2015-05-04 12:48 UTC
From: wowkise at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: PDO MySQL
PHP Version: 5.5.24 OS: Centos
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wowkise at gmail dot com
New email:
PHP Version: OS:

 

 [2015-05-04 12:00 UTC] wowkise at gmail dot com
Description:
------------
infinite results and huge CPU usage

Test script:
---------------
<?php

$pdo = new \PDO('mysql:host=localhost;dbname=test', 'test', 'test');
$db  = new db( $pdo );
class db
{
    public function __construct(\PDO &$pdo = null, array $options = []) { $this->pdo = $pdo; }
    public function query( $sql, array $bind = [], array $options = [])
    {
        $stmt = $this->pdo->prepare($sql);
        $stmt->execute($bind);
        return $stmt;
    }
}
$sql = "SELECT change_id as id FROM ac_changelog LIMIT 10";
while( $row = $db->query( $sql )->fetch() )
{
    echo $row['id'] . PHP_EOL;
}

?>



Expected result:
----------------
10 results returned.

Actual result:
--------------
infinite results and huge CPU usage and until the process is killed.

changing code to 

$stmt = $db->query( $sql );

while( $row = $stmt->fetch() )
{
    echo $row['id'] . PHP_EOL;
}

fixes the problem.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-04 12:48 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-05-04 12:48 UTC] cmb@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

The while loop in the test script causes the query to be repeately executed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 12:01:29 2024 UTC