Current location: Hot Scripts Forums » Programming Languages » PHP » Importing to a mysql database via php


Importing to a mysql database via php

Reply
  #1 (permalink)  
Old 01-22-04, 10:31 PM
gulfan gulfan is offline
New Member
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Importing to a mysql database via php

I’m having some problems moving a mysql database from one server to another. I’ve managed to export the database and ftp it to the server. I don’t have SSH access on the server so I’m unable to do a normal import like this:

mysql -uUSERNAME -p newdbname < /path/to/dump.sql

So I’m trying to do it using a php script but I’m not having much luck with it.

PHP Code:

<?php


$dbh 
mysql_connect('localhost''viforum_viforum''PASSWORD') or die(mysql_error() . " :: mysql_connect error");
$sdb mysql_select_db('viforum_viforum'$dbh);

mysql_query(file_get_contents('forumbackup-01-22-2004.sql'));

?>
The script is in the same directory as forumbackup-01-22-2004.sql and when executed it doesn’t return any errors. I’m not sure what I’m doing wrong, or if what I want to accomplish is even possible.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-23-04, 05:44 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

You may get some errors that may ring the bell by rewriting the last line as follows:

PHP Code:

$res mysql_query(file_get_contents('forumbackup-01-22-2004.sql'));

if (!
$res) {
      echo 
'Query Failed (ErrNo: '.mysql_errno().') '.mysql_error()';

Also, if you are trying to excute INSERT statements, there is a LOAD FILE statements in MySQL that suck up your CSV files, rather than INSERT statements, which they claim is faster.

If this doesn't help, then if you could share a couple of lines from forumbackup-01-22-2004.sql (assuming those are INSERT) and corresponding table definitions, it may be faster.

Good luck.
__________________
Blavv =|
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 07:02 AM
Connect to MySQL with PHP demiann PHP 3 01-11-04 03:24 PM
Pulling data from MySQl Database w/ PHP? dayzeday PHP 6 10-07-03 08:01 AM
Send sms via php and mysql database help meeeeee eggdesign PHP 2 10-03-03 01:29 AM


All times are GMT -5. The time now is 07:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.