Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database dumb

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I took this code from the php nuke script and Im trying it in mine.

the only problem is all the 'insert into''s is one big line and i cant execute it on my site like that.

here is the code:

Code:
			$crlf="\n";

		$strNoTablesFound = "No tables found in database.";
		$strHost = "Host";
		$strDatabase = "Database ";
		$strTableStructure = "Table structure for table";
		$strDumpingData = "Dumping data for table";
		$strError = "Error";
		$strSQLQuery = "SQL-query";
		$strMySQLSaid = "MySQL said: ";
		$strBack = "Back";
		$strFileName = "Save Database";
		$strName = "Database saved";
		$strDone = "On";
		$strat = "at";
		$strby = "by";
		$date_jour = date ("m-d-Y");
		
		header("Content-disposition: filename=$db backup - $date_jour.sql");
		header("Content-type: application/octetstream");
		header("Pragma: no-cache");
		header("Expires: 0");
		$client = getenv("HTTP_USER_AGENT");
		if(ereg('[^(]*\((.*)\)[^)]*',$client,$regs)) 
		{
		$os = $regs[1];
		// this looks better under WinX
		if (eregi("Win",$os)) 
		    $crlf="\r\n";
		}
		
		
		function my_handler($sql_insert)
		{
		    global $crlf;
		    echo "$sql_insert;$crlf";
		}

		function get_table_content($db, $table, $handler)
		{
		    $result = mysql_db_query($db, "SELECT * FROM $table") or mysql_die();
		    $i = 0;
		    while($row = mysql_fetch_row($result))
		    {

		        $table_list = "(";
		
		        for($j=0; $j<mysql_num_fields($result);$j++)
		            $table_list .= mysql_field_name($result,$j).&quot;, &quot;;
		
		        $table_list = substr($table_list,0,-2);
		        $table_list .= &quot;)&quot;;
		
		        if(isset($GLOBALS[&quot;showcolumns&quot;]))
		            $schema_insert = &quot;INSERT INTO $table $table_list VALUES (&quot;;
		        else
		            $schema_insert = &quot;INSERT INTO $table VALUES (&quot;;
		
		        for($j=0; $j<mysql_num_fields($result);$j++)
		        {
		            if(!isset($row[$j]))
		                $schema_insert .= &quot; NULL,&quot;;
		            elseif($row[$j] != &quot;&quot;)
		                $schema_insert .= &quot; '&quot;.addslashes($row[$j]).&quot;',&quot;;
		            else
		                $schema_insert .= &quot; '',&quot;;
		        }
		        $schema_insert = ereg_replace(&quot;,$&quot;, &quot;&quot;, $schema_insert);
		        $schema_insert .= &quot;)&quot;;
		        $schema_insert .= &quot;$crlf&quot;;
		        $handler(trim($schema_insert));
		        $i++;
		    }
		    return (true);
		}
		
		function get_table_def($db, $table, $crlf)
		{
		    $schema_create = &quot;&quot;;
		    $schema_create .= &quot;DROP TABLE IF EXISTS $table;$crlf&quot;;
		    $schema_create .= &quot;CREATE TABLE $table ($crlf&quot;;
		
		    $result = mysql_db_query($db, &quot;SHOW FIELDS FROM $table&quot;) or mysql_die();
		    while($row = mysql_fetch_array($result))
		    {
		        $schema_create .= &quot;   $row[Field] $row[Type]&quot;;
		
		        if(isset($row[&quot;Default&quot;]) && (!empty($row[&quot;Default&quot;]) || $row[&quot;Default&quot;] == &quot;0&quot;))
		            $schema_create .= &quot; DEFAULT '$row[Default]'&quot;;
		        if($row[&quot;Null&quot;] != &quot;YES&quot;)
		            $schema_create .= &quot; NOT NULL&quot;;
		        if($row[&quot;Extra&quot;] != &quot;&quot;)
		            $schema_create .= &quot; $row[Extra]&quot;;
		        $schema_create .= &quot;,$crlf&quot;;
		    }
		    $schema_create = ereg_replace(&quot;,&quot;.$crlf.&quot;$&quot;, &quot;&quot;, $schema_create);
		    $result = mysql_db_query($db, &quot;SHOW KEYS FROM $table&quot;) or mysql_die();
		    while($row = mysql_fetch_array($result))
		    {
		        $kname=$row['Key_name'];
		        if(($kname != &quot;PRIMARY&quot;) && ($row['Non_unique'] == 0))
		            $kname=&quot;UNIQUE|$kname&quot;;
		         if(!isset($index[$kname]))
		             $index[$kname] = array();
		         $index[$kname][] = $row['Column_name'];
		    }
		
		    while(list($x, $columns) = @each($index))
		    {
		         $schema_create .= &quot;,$crlf&quot;;
		         if($x == &quot;PRIMARY&quot;)
		             $schema_create .= &quot;   PRIMARY KEY (&quot; . implode($columns, &quot;, &quot;) . &quot;)&quot;;
		         elseif (substr($x,0,6) == &quot;UNIQUE&quot;)
		            $schema_create .= &quot;   UNIQUE &quot;.substr($x,7).&quot; (&quot; . implode($columns, &quot;, &quot;) . &quot;)&quot;;
		         else
		            $schema_create .= &quot;   KEY $x (&quot; . implode($columns, &quot;, &quot;) . &quot;)&quot;;
		    }
		
		    $schema_create .= &quot;$crlf)&quot;;
		    return (stripslashes($schema_create));
		}
		
		function mysql_die($error = &quot;&quot;)
		{
		    echo &quot;<b> $strError </b><p>&quot;;
		    if(isset($sql_query) && !empty($sql_query))
		    {
		        echo &quot;$strSQLQuery: <pre>$sql_query</pre><p>&quot;;
		    }
		    if(empty($error))
		        echo $strMySQLSaid.mysql_error();
		    else
		        echo $strMySQLSaid.$error;
		    echo &quot;<br><a href=\&quot;javascript:history.go(-1)\&quot;>$strBack</a>&quot;;
		    exit;
		}
		
		include '../config.php';

		$dbi = mysql_connect (&quot;$server&quot;, &quot;$user&quot;, &quot;$pass&quot;) or die (&quot;Error connecting.&quot;);
		mysql_select_db (&quot;$db&quot;) or die (&quot;Error selecting database.&quot;);
		
		$tables = mysql_list_tables($db);
		
		$num_tables = @mysql_numrows($tables);
		if($num_tables == 0)
		{
		    echo $strNoTablesFound;
		}
		else
		{
		    $i = 0;
		    $heure_jour = date(&quot;H:i&quot;);
		    print &quot;# ========================================================$crlf&quot;;
		    print &quot;#$crlf&quot;;
		    print &quot;# $strName : $db$crlf&quot;;
		    print &quot;# $strDone $date_jour $strat $heure_jour $strby $_COOKIE[stregis_username]!$crlf&quot;;
		    print &quot;#$crlf&quot;;
		    print &quot;# ========================================================$crlf&quot;;
		    print &quot;$crlf&quot;;
		    
		    while($i < $num_tables)
		    { 
		        $table = mysql_tablename($tables, $i);
		
		        print $crlf;
		        print &quot;# --------------------------------------------------------$crlf&quot;;
		        print &quot;#$crlf&quot;;
		        print &quot;# $strTableStructure '$table'$crlf&quot;;
		        print &quot;#$crlf&quot;;
		        print $crlf;
		
		        echo get_table_def($db, $table, $crlf).&quot;;$crlf$crlf&quot;;
		        
			print &quot;#$crlf&quot;;
			print &quot;# $strDumpingData '$table'$crlf&quot;;
			print &quot;#$crlf&quot;;
			print $crlf;
			
			get_table_content($db, $table, &quot;my_handler&quot;);
		
		        $i++;

		    }
		}

can someone please help me? thanks
 
Ive already fixed it

I changed:

function my_handler($sql_insert)
{
global $crlf;
echo &quot;$sql_insert;$crlf&quot;;
}

to:

function my_handler($sql_insert)
{
$crlf = &quot;\r\n&quot;;
echo &quot;$sql_insert;$crlf&quot;;
}

simple, huh?

lol
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top