test.txt
mysql
xxx
<?php
ini_set("max_execution_time", "180");//避免数据量过大,导出不全的情况出现。
$host="localhost";//数据库地址
//$dbname="mysql";//这里配置数据库名
$username="root";//用户名
$passw="toor";//这里配置密码$i = 0;
$crlf="\r\n";
global $dbconn;
$dbconn = mysql_connect($host,$username,$passw) or die("Unable to connect to the MySQL!");$handle= fopen("/tmp/test.txt","r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
try{
$dbname = $line;
echo $dbname;
$db = mysql_select_db($dbname,$dbconn);
mysql_query("SET NAMES 'utf8'");
$tables =mysql_list_tables($dbname,$dbconn);
$num_tables = @mysql_numrows($tables);
while($i < $num_tables)
{
$table=mysql_tablename($tables,$i);
print $crlf;
echo get_table_content($dbname, $table, $crlf);
$i++;
} }catch(Exception $e){
echo 'Caught exception: ', $e->getMessage(), "\n";
}
} fclose($handle);
} else {
} echo "done.\n";
exit;
//获得表内容
function get_table_content($db, $table, $crlf)
{
$schema_create = "";
$temp = "";
$result = mysql_db_query($db, "SELECT * FROM $table");
$i = 0;
while($row = mysql_fetch_row($result))
{
$schema_insert = "INSERT INTO `$table` VALUES (";
for($j=0; $j<mysql_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= " NULL,";
elseif($row[$j] != "")
$schema_insert .= " '".addslashes($row[$j])."',";
else
$schema_insert .= " '',";
}
$schema_insert .= ");$crlf";
$temp = $temp.$schema_insert ;
$i++;
}
return $temp;
}
?>
mysql
xxx
<?php
ini_set("max_execution_time", "180");//避免数据量过大,导出不全的情况出现。
$host="localhost";//数据库地址
//$dbname="mysql";//这里配置数据库名
$username="root";//用户名
$passw="toor";//这里配置密码$i = 0;
$crlf="\r\n";
global $dbconn;
$dbconn = mysql_connect($host,$username,$passw) or die("Unable to connect to the MySQL!");$handle= fopen("/tmp/test.txt","r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
try{
$dbname = $line;
echo $dbname;
$db = mysql_select_db($dbname,$dbconn);
mysql_query("SET NAMES 'utf8'");
$tables =mysql_list_tables($dbname,$dbconn);
$num_tables = @mysql_numrows($tables);
while($i < $num_tables)
{
$table=mysql_tablename($tables,$i);
print $crlf;
echo get_table_content($dbname, $table, $crlf);
$i++;
} }catch(Exception $e){
echo 'Caught exception: ', $e->getMessage(), "\n";
}
} fclose($handle);
} else {
} echo "done.\n";
exit;
//获得表内容
function get_table_content($db, $table, $crlf)
{
$schema_create = "";
$temp = "";
$result = mysql_db_query($db, "SELECT * FROM $table");
$i = 0;
while($row = mysql_fetch_row($result))
{
$schema_insert = "INSERT INTO `$table` VALUES (";
for($j=0; $j<mysql_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= " NULL,";
elseif($row[$j] != "")
$schema_insert .= " '".addslashes($row[$j])."',";
else
$schema_insert .= " '',";
}
$schema_insert .= ");$crlf";
$temp = $temp.$schema_insert ;
$i++;
}
return $temp;
}
?>
$dbname = $line;
echo $dbname;这个结果是什么?
$db
就没有结果了,什么都没有了
$num_tables = @mysql_numrows($tables);
把这个@ 去掉然后看一下有没有报错信息