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
Importing Small Database From SQL file
Old 12-16-2008, 03:10 PM Importing Small Database From SQL file
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
So I have the file db.sql, and its only a few kilobytes, so very small, but I can't figure out how I would import it in to my database through a PHP script. I tried some code that broke it up query by query but it did not get fully imported.

thanks
melefire is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-16-2008, 03:23 PM Re: Importing Small Database From SQL file
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
use phpMyAdmin. It should be available from your control panel.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-16-2008, 03:34 PM Re: Importing Small Database From SQL file
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
that would work to import my database, but I am writing an install script, so i need to know how to do this in php code
melefire is offline
Reply With Quote
View Public Profile
 
Old 12-16-2008, 03:56 PM Re: Importing Small Database From SQL file
Average Talker

Posts: 15
Trades: 0
Hello melefire...

I don't know if this is much help, but I thought I'd try and help out at a chance it was. I've used it with CSVs and hopefully you can use it for SQL.

Check out this page

http://dev.mysql.com/doc/refman/5.1/en/load-data.html

I managed to load a CSV file into MySQL really easily with this so it might be your way forward. That said someone who knows their stuff might dive in with something better... either way I hope this has been of some use!

Regards,

Leonard

PS... The query string I used was...
"LOAD DATA LOCAL INFILE './$filename' INTO TABLE $dbtable FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'"

Last edited by Gentleman_; 12-16-2008 at 03:58 PM..
Gentleman_ is offline
Reply With Quote
View Public Profile
 
Old 12-16-2008, 04:04 PM Re: Importing Small Database From SQL file
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
simply use a command line
PHP Code:
$run="mysql -u $user -p$password $db < file.sql";
exec($run); 
Looking in the comment on the php manual, I've seen this: http://www.php.net/manual/en/functio...uery.php#85876
As far as I know, it reads the sql file and sends the query one after the other, but should be able to cope with multilines statements.
It could be worth a try.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 12-16-2008, 04:20 PM Re: Importing Small Database From SQL file
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
thanks for the help, but on my server the exec command is disabled. Also i tried out that function you mentioned and it didn't work.
melefire is offline
Reply With Quote
View Public Profile
 
Old 12-16-2008, 04:25 PM Re: Importing Small Database From SQL file
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
just put the queries into strings and call them with mysql_query($command_string)
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Importing Small Database From SQL file
 

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.31910 seconds with 12 queries