mysqli and pdo

From: Date: Sat, 26 Jun 2004 22:10:51 +0000
Subject: mysqli and pdo
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-893@lists.php.net to get a copy of this message
A suggestion for mysqli and pdo.. One of the most common things I can think of that I do when accessing datasets in a database is pull multiple rows of data in a single query. Loop through all the rows, build an array and pass it on to a template or some other "handler" So in the past I have had fetchall_assoc() function that fetches all rows into a single array. Working with php 5, pdo doesnt have a php 5 pluggin yet and I tried extending mysqli object to create a fetchall_assoc but since $mysqli->query() returns a internal results object Im having a problem doing this. What I suggest ( using a example from an object library for mysql )
    function fetchall_assoc($callback = '') {
        $results = array();
        while($row = $this->fetch_assoc()) {
            if($callback) {
                $row =  call_user_func($callback, $row);
            }
            $results[] = $row;
        }
        return $results;
    }
The callback allows you to make changes to each row while pulling the data instead of having to reloop through everthing again. Anyway just a comment/request/suggestion. Of course if someone can slap me with a way to do this with mysqli object I would go back to my chair and hide. -- Richard Thomas Cyberlot Technologies Group Inc. 507.398.4124 - Voice

« previous php.pecl.dev (#893) next »