TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-25-2010, 02:33 AM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Application Export table to sql

Good day to you,
I have added an options to my db production site which is to back up the table into csv file, see code below.

Now I would like to be able to export to sql file, how would I do it without using phpMyadmin , I would like to use a function like the following.

PHP Code:
<?php
$host 
'localhost';
$user '....';
$pass '....';
$db '....';
$table $_GET[table];
$file 'export';

$link mysql_connect($host$user$pass) or die("Can not connect." mysql_error());
mysql_select_db($db) or die("Can not connect.");

$result mysql_query("SHOW COLUMNS FROM ".$table."");
$i 0;
if (
mysql_num_rows($result) > 0) {
while (
$row mysql_fetch_assoc($result)) {
$csv_output .= $row['Field']."; ";
$i++;
}
}
$csv_output .= "\n";

$values mysql_query("SELECT * FROM ".$table."");
while (
$rowr mysql_fetch_row($values)) {
for (
$j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\n";
}

$filename "Backup__".$table."__".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" date("Y-m-d") . ".csv");
header"Content-disposition: filename=".$filename.".csv");
print 
$csv_output;
exit;
echo 
"Exporting...";
?>

Thanks!
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 05-25-2010, 06:23 AM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

A couple minutes on google found this: http://davidwalsh.name/backup-mysql-database-php. It's only does the basics, but it should not be too hard to modify it to fit your needs.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
feedback on my class please frostyboy33 Advanced PHP Programming 7 10-22-2012 09:12 AM
Databse structure Village Idiot TalkPHP Developer Team 3 01-16-2009 10:31 PM
This project has begun! Village Idiot TalkPHP Developer Team 40 01-01-2009 04:29 AM
SQL injections protection Rendair Tips & Tricks 23 12-11-2007 03:59 PM
Export as SQL from mySQL using cron job datahound MySQL & Databases 5 12-08-2007 12:18 AM


All times are GMT. The time now is 12:56 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design