Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Copy mySQL table via php code?
Old 02-06-2009, 10:14 AM Copy mySQL table via php code?
Average Talker

Posts: 26
Trades: 0
Can you copy the structure and data of a mySQL table using a php code? Any help appreciated, cannot find it wiv Google..
PauloMillerz is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-06-2009, 10:36 AM Re: Copy mySQL table via php code?
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
I'm sure there's something in the comments on this page.
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

Another probably helpful link:
http://www.php-mysql-tutorial.com/wi...databases.aspx
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-06-2009, 02:25 PM Re: Copy mySQL table via php code?
Average Talker

Posts: 26
Trades: 0
Cool will take a loook
PauloMillerz is offline
Reply With Quote
View Public Profile
 
Old 02-06-2009, 02:31 PM Re: Copy mySQL table via php code?
Average Talker

Posts: 26
Trades: 0
Quote:
Execute a database backup query from PHP file

Below is an example of using SELECT INTO OUTFILE query for creating table backup :

<?php
include 'config.php';
include 'opendb.php';
$tableName = 'mypet';
$backupFile = 'backup/mypet.sql';
$query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);

include 'closedb.php';
?>
To restore the backup you just need to run LOAD DATA INFILE query like this :

<?php
include 'config.php';
include 'opendb.php';
$tableName = 'mypet';
$backupFile = 'mypet.sql';
$query = "LOAD DATA INFILE 'backupFile' INTO TABLE $tableName";
$result = mysql_query($query);

include 'closedb.php';
?>
It's a good idea to name the backup file as tablename.sql so you'll know from which table the backup file is
Am I reading the logic of that right? I read it that it saves the table in the sql file and then the second one reads it and writes that into another table, based on the variables set? If so.. that would work for me..

Last edited by PauloMillerz; 02-06-2009 at 02:32 PM..
PauloMillerz is offline
Reply With Quote
View Public Profile
 
Old 02-06-2009, 02:33 PM Re: Copy mySQL table via php code?
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Yea, I'd say it does. :P
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-06-2009, 02:58 PM Re: Copy mySQL table via php code?
Average Talker

Posts: 26
Trades: 0
Quote:
Originally Posted by Insensus View Post
Yea, I'd say it does. :P

Grrr... tried that.. it runs with no errors.. but i cannot locate the sql file.. hmm
PauloMillerz is offline
Reply With Quote
View Public Profile
 
Old 02-06-2009, 03:33 PM Re: Copy mySQL table via php code?
Average Talker

Posts: 26
Trades: 0
I used this to do what I wanted:

Quote:
CREATE TABLE student2 SELECT * FROM student
Thanks for help ! ~>
PauloMillerz is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Copy mySQL table via php code?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25530 seconds with 12 queries