Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save var_dump into text file [closed]

I have the php code for sql query

<?  $server = "127.0.0.1";  $username = "root";  $password = "1";    $link= connecttodb($server,$username,$password);    function connecttodb($server,$username,$password)  {        $rez=fopen("test.txt","ab");      if ($link=mysql_connect ("$server","$username","$password",TRUE))      {          fwrite($rez,"".$server." \r\n");  	    echo "Connected successfully to >> " .$server ;  		  		$result = mysql_query('SHOW DATABASES');          echo "<br>";          while ($row = mysql_fetch_array($result))          {              var_dump ($row); }  	    }      }      ini_set('max_execution_time', 10);      return $link;  ?>

this code print my database name on the browser how I can save the database name into text file

Connected successfully to >> 127.0.0.1  array(2) { [0]=> string(18) "information_schema" ["Database"]=> string(18) "information_schema" } array(2) { [0]=> string(2) "db" ["Database"]=> string(2) "db" } array(2) { [0]=> string(5) "mysql" ["Database"]=> string(5) "mysql" } array(2) { [0]=> string(10) "phpmyadmin" ["Database"]=> string(10) "phpmyadmin" } array(2) { [0]=> string(4) "test" ["Database"]=> string(4) "test" }
like image 864
Yasser Abo Reida Avatar asked Aug 12 '16 23:08

Yasser Abo Reida


People also ask

What is the difference between Var_dump () and Print_r ()?

var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.

What does Var_dump return?

@JMTyler var_export returns a parsable string—essentially PHP code—while var_dump provides a raw dump of the data. So, for example, if you call var_dump on an integer with the value of 1, it would print int(1) while var_export just prints out 1 .

Why Var_dump () is preferable over Print_r ()?

It's too simple. The var_dump() function displays structured information about variables/expressions including its type and value. Whereas The print_r() displays information about a variable in a way that's readable by humans. Example: Say we have got the following array and we want to display its contents.

Is there a Var_dump in JavaScript?

The var_dump equivalent in JavaScript? Simply, there isn't one. Prints an interactive listing of all properties of the object. This looks identical to the view that you would see in the DOM tab.


1 Answers

You can use the output buffering functions to capture output and write it to a file.

ob_flush(); ob_start(); while ($row = mysql_fetch_assoc($result)) {     var_dump($row); } file_put_contents("dump.txt", ob_get_flush()); 
like image 91
Barmar Avatar answered Sep 26 '22 05:09

Barmar