MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old December 24th, 2003, 04:39 PM
mwichmann4 mwichmann4 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 80 mwichmann4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 45 sec
Reputation Power: 5
Quick mysql dump from file using php

hey everyone,

looking for a quick way to read a file holding the mysql
table dump and dumping it into mysql. I got it down to where
it is reading the dump file, but what command do i use to execute it against the db? Thanks
__________________
Nothing is Everything

Reply With Quote
  #2  
Old December 27th, 2003, 12:04 AM
Mike_r Mike_r is offline
ExoCrew
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 68 Mike_r User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Simplest way is to do through phpMyadmin but sometimes phpMyAdmin gives memory problems and sometimes it takes tooooooooo long time.. And it may happen that query wont be executed.

It happened to me so i wrote a script to do it myself.


PHP Code:
<?php

$db 
mysql_connect 'localhost''username''password' );
mysql_select_db'database'$db );

$FP fopen 'backup.sql''r' );
$READ fread $FPfilesize 'backup.sql') );

$READ explode ";\n"$READ );

foreach ( 
$READ AS $RED )
{
    
mysql_query $RED );
}

echo 
'Done';
?>


Replace the backup.sql with your file name.
I used this to execute a phpBB mySQL dump into the database.

Hope that helps.
__________________
ExoHelpDesk
ExoCrew Free Services

Reply With Quote
  #3  
Old December 27th, 2003, 10:18 AM
mwichmann4 mwichmann4 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 80 mwichmann4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 45 sec
Reputation Power: 5
ya it does thanks so much, quick question though. What are u doing with the explode function there.

Reply With Quote
  #4  
Old December 27th, 2003, 09:38 PM
Mike_r Mike_r is offline
ExoCrew
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 68 Mike_r User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Explode() function there is splitting the readed file with the ; and a line break

for example :

INSERT INTO table (id,name) VALUES ('ok','notok');
INSERT INTO table2 *********;

These are both are splitted and each gets executed.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Quick mysql dump from file using php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway