tags:

views:

49

answers:

3

Hi,

It is like continue getting data from mysql using PHP and simultaneously stream out to the http.

Like in java we can write into ServletOutput stream?

The size of the data can be like 200 MB.

Thanks

A: 

It sounds like you need PHP or some equivalent... Can you be more specific as to what you are trying to do?

EToreo
Edited.........
Vishal
A: 

I think you are looking to flush the output buffer in PHP. For more information see the flush function and the other output control functions in the PHP manual.

John
I think its "flush" what I wanted but definitely need to look at the documentation. Thanks :)
Vishal
+1  A: 

Here's a script that executes several select statements on a table and writes each result row to the output stream. It really does no differently than echoing, but maybe you can adapt it, e.g., by using a different stream wrapper (predefined or custom). Add security and error-checking code, of course.

Supposing a table containing fields "name" and "home_country".

$dsn = 'mysql:host=localhost;dbname=test';
$uname = 'uname';
$pword = 'password';
$countries = array('Mexico', 'Egypt', 'Estonia', 'Australia');

$pdo = new PDO($dsn, $uname, $pword);
$qry_stmnt = 'SELECT name, home_country 
              FROM places_test 
              WHERE home_country = :country';
$stmnt = $pdo->prepare($qry_stmnt);

$out_stream = fopen('php://output', 'w');
foreach ($countries as $country) {
    $result = $stmnt->execute(array(':country' => $country));
    $obj = $stmnt->fetchAll(PDO::FETCH_OBJ);
    foreach ($obj as $row) {
        fwrite($out_stream, $row->name . ': ' . $row->home_country . '<br />');
    }
}
fclose($out_stream);
GZipp
@Vishal - I just noticed that you asked this question earlier, and didn't respond to any of the answers, and that you have an 11% accept rate. I hope I haven't wasted my time.
GZipp
@GZipp, Appreciate your response and the code snippet, I am looking closely to all the responses so as soon as I get an expected answer I will close it :).
Vishal
OK :) Thanks. I see you've accepted a good answer.
GZipp