LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-24-2006, 12:21 AM   #1
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Rep: Reputation: 30
PHP / MySQL importing *.dmp


I'm running into an annoying problem. I've been trying to get a few strings to work in PHP and they have not been successful.

For example, this line in bash:
Code:
mysql -pPassword -e'drop table table_members;' databasename_db
works in a bash script.

However, this line in PHP:
Code:
system("mysql -pPassword -e'drop table table_members;' databasename_db");
does not.

After hard core studying, I found a way to work this out. Here's how:
Code:
	mysql_connect(localhost, username, password);
	mysql_select_db(databasename_db);
	mysql_query("DROP TABLE table_members");
But now I'm in a serious stump because this line:
Code:
system("mysql -pPassword databasename_db < /var/www/html/dumpfile.dmp");
does not work either!

I've been google'ing this for a LONG TIME! I can't find an answer!

I need someone to show me how to do the following:
Code:
mysql -pPassword databasename_db < /var/www/html/dumpfile.dmp
in PHP!
 
Old 02-24-2006, 01:47 AM   #2
thermite_1033
Member
 
Registered: May 2004
Location: Antwerp, Belgium
Distribution: slackware
Posts: 112

Rep: Reputation: 18
mysql_connect(localhost, username, password);
mysql_select_db(databasename_db);
mysql_query("system /path/to dump");

try this
 
Old 02-24-2006, 02:21 AM   #3
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
Tried, doesn't work. FYI, the dump file has garbage in it. For some reason, the garbage is ignored when importing the file into mysql from the bash script line. Yet, it is not ignored when importing from PHP. If the garbage is thrown out, and the file content is split in two (table creation and data for table), PHP can recreate the table and restore the data. For all this work, I'll be making 200 lines of code just so PHP can respond to file dump import request. Where as, I can simply make 7 lines in bash to recycle the process every 5 minutes automatically. Why PHP is so much more complex for something so simple, I don't know. But what I do know is that PHP should be far better then BASH, and BASH is making PHP look really stupid to use.

Last edited by dolvmin; 02-24-2006 at 02:29 AM.
 
Old 02-25-2006, 03:51 AM   #4
thermite_1033
Member
 
Registered: May 2004
Location: Antwerp, Belgium
Distribution: slackware
Posts: 112

Rep: Reputation: 18
sorry, i mentioned the wrong command
it should be

mysql_query("source /path/to dump");


or this i found on http://be2.php.net/function.mysql-query

PHP Code:
<?php
  
function parse_mysql_dump($url$ignoreerrors false) {
   
$file_content file($url);
   
$query "";
   foreach(
$file_content as $sql_line) {
     
$tsl trim($sql_line);
     if ((
$sql != "") && (substr($tsl02) != "--") && (substr($tsl01) != "#")) {
       
$query .= $sql_line;
       if(
preg_match("/;\s*$/"$sql_line)) {
         
$result mysql_query($query);
         if (!
$result && !$ignoreerrors) die(mysql_error());
         
$query "";
       }
     }
   }
  }
?>
 
  


Reply


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem importing database back to MySql shubb Programming 3 11-29-2005 01:36 PM
Mysql importing problem nepcw Linux - Newbie 4 03-22-2004 05:09 PM
mysql importing inq Robin01 Linux - Newbie 1 11-30-2003 09:12 AM
MySQL: Importing a database from an XML file concoran General 0 09-08-2003 02:58 AM
Importing FreeBSD mysql database to RedHat Linux 7.3 RKris Linux - Software 6 05-06-2003 04:07 AM


All times are GMT -5. The time now is 06:46 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration