PHP Classes
elePHPant
Icontem

File: demo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of fridayana baabullah  >  Limit Result Set Iterator  >  demo.php  >  Download  
File: demo.php
Role: Example script
Content type: text/plain
Description: Demo script.
Class: Limit Result Set Iterator
Retrieve a limited range of SQL query results
Author: By
Last change:
Date: 6 years ago
Size: 1,749 bytes
 

Contents

Class file image Download
<?php

// Example of Use

require_once("PhpMysqlLimitResultSetIterator.php");

// SETUP DB CONNECTION (Optionally)
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "training";
$db_table = "my_table";
$create_table = true;

$conn = mysql_connect($db_host, $db_user, $db_pass) or die("Cannot connect to database");
mysql_select_db($db_name);

if (
$create_table) {
   
$sql = "DROP TABLE IF EXISTS $db_table";
   
mysql_query($sql);
   
   
$sql = "
        CREATE TABLE
$db_table (
            `id` int(11) NOT NULL auto_increment,
            `message` varchar(255) collate latin1_general_ci default NULL,
            PRIMARY KEY (`id`)
        )
    "
;
   
mysql_query($sql);

   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
   
$sql = "INSERT INTO $db_table (message) VALUES ('tes')"; mysql_query($sql);
}

$chunkSize = 1000;
$sql = "select * from $db_table";
$iterator = new PhpMysqlLimitResultSetIterator($conn, $sql, $chunkSize);

foreach (
$iterator as $row) {
    echo
$row->id . "," . $row->message . "\n";
}