Jump to content

txt file mysql


shage

Recommended Posts

I think this might be what you are looking for.

 

It basically goes through all the tables in your database and then takes the column sitename (which obviusly you will need to change to suit your needs) and goes through each value. It is all added to the variable $string which is then written into the db.txt which you will need to create one and name it what ever you want.

 

<?php
$db_host = '';
$db_username = '';
$db_password = '';
$db_database = '';

$db_connection = mysql_connect($db_host,$db_username,$db_password) or die(mysql_error());
mysql_select_db($db_database) or die(mysql_error());

$string = "";

$sql = "SHOW TABLES FROM $db_database";
$result = mysql_query($sql) or die(mysql_error());
while($table_name = mysql_fetch_array($result))
{
$sql2 = "SELECT sitename FROM $table_name[0]";
$result2 = mysql_query($sql2) or die(mysql_error());
$string .= "\n{$table_name[0]}\n";
while($column_name = mysql_fetch_array($result2))
{
	$string .= "{$column_name[0]}\n";
}
}

$file = "db.txt";
if(is_writable($file))
{
    if(!$handle = fopen($file, 'w'))
{
        die("Cannot open file ($file)");
    }
    if(fwrite($handle, $string) === FALSE)
{
        die("Cannot write to file ($file)");
    }

    echo "Success, wrote to file ($file)";

    fclose($handle);

} else
{
	echo "The file $file is not writable";
}
?>

 

I hope it helps ;D

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/80281-txt-file-mysql/#findComment-406940
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.