PHP Classes

File: usage.php

Recommend this page to a friend!
  Classes of Matthew Daniel   Multiple PHP PDOStatement Iterator   usage.php   Download  
File: usage.php
Role: Example script
Content type: text/plain
Description: Example of how to use it
Class: Multiple PHP PDOStatement Iterator
Iterate over multiple query results using PDO
Author: By
Last change:
Date: 11 years ago
Size: 1,061 bytes
 

Contents

Class file image Download
<?php

// multiRecordsetItorator class
//
// This is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See <http://www.gnu.org/licenses/>.

$conn = new PDO('mysql:host=localhost;dbname=csproofing.coursestage.local', 'root', 'password');

$recordset1 = $conn->query("SELECT id, username FROM mdl_user where id IN (1,2,3,4,5,10, 11, 12) order by id DESC");
$recordset2 = $conn->query("SELECT id, firstname, lastname FROM mdl_user where id IN (1,3,6,7,9) order by id DESC");

$test = new multiPDOStatementIterator('id', multiPDOStatementIterator::DESC, $recordset1, $recordset2);

foreach (
$test as $record) {
   
var_dump($record);
}