I think instead of
ob_get_flush()
You want
$var = ob_get_clean();
file_put_contents("$server.txt", $var );
To put it all togather you would need to do this
while ($row = mysql_fetch_assoc($result)) {
ob_start();
var_dump($row);
file_put_contents("$server.txt",ob_get_clean());
}
http://php.net/manual/en/function.ob-get-clean.php
Get current buffer contents and delete current output buffer ...
Returns the contents of the output buffer and end output buffering. If output buffering isn't active then FALSE is returned.
-Note- the end output buffering
this is why we need to restart it ob_start()
on each iteration of the loop.
For ob_get_flush()
The output buffer must be started by ob_start() with
PHP_OUTPUT_HANDLER_FLUSHABLE flag. Otherwise ob_get_flush() will not
work.
That said it may not be the best approach for your goal. As an alternative method, you can use this function
function getVarType( $var, $escapeHtml = true ){
$strArg = 'unknown';
switch ( gettype( $var ) ){
case 'boolean':
return ( $var ? 'true' : 'false' );
case 'integer':
return intval( $var );
case 'double':
return floatval( $var );
case 'string':
if( $escapeHtml ){
$var = htmlentities( $var, ENT_NOQUOTES, 'UTF-8', false);
}
return "'".$var."'";
case 'resource':
return 'Resource id #'.intval( $var );
case 'NULL':
return 'NULL';
case 'array':
return "Array";
case 'object':
return 'Object('.get_class( $var ).')';
case 'unknown type':
default:
return'UNKNOWN TYPE';
}
}
$row = array_map( 'getVarType', $row );
However I think in PHP 7 they reversed the Parameters for array map. This is from an Exception/Error handling class I just wrote, you can modify it to more closely match var_dump if you want. Currently, it's setup to match the exception stack trace printout.
By the way if you want a really killer debuggin class, you can use the one from my framework
https://github.com/ArtisticPhoenix/Evo/blob/master/EVO/Debug.php
With some small modification it may fit your needs ( perhaps a bit overkill )
This is what it outputs
$G = ['one'=>1, 'two' => 2, 3=>['foo', 'bar']];
EVO_Debug::dump( $G );
==================================== EVO_DEBUG::DUMP =====================================
Output from FILE[ C:\UniServerZ\www\Evo\EVO\bootstrap.php ] on LINE[ 72 ]
------------------------------------------------------------------------------------------
array(3){
["one"] => int(1),
["two"] => int(2),
[3] => array(2){
[0] => string(3) "foo",
[1] => string(3) "bar",
},
}
==========================================================================================
Although you want to use
EVO_Debug::export( $G );
It can also output private properties, and class constants. I only post the link because it's not trivial to deal with all the possible variable types, and it doesn't help here that PHP is Non-Typed language.