将var_dump保存到文本文件中 [英] save var_dump into text file
本文介绍了将var_dump保存到文本文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有用于SQL查询的php代码
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" }
推荐答案
您可以使用输出缓冲功能来捕获输出并将其写入文件.
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());
这篇关于将var_dump保存到文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文