ky0shiro Posted July 6, 2007 Share Posted July 6, 2007 Hi, all.. wanna ask for help please i have already backup my database into a file named backup.sql from phpmyadmin.. now i want to make an interface using php to restore it like phpmyadmin too, does anybody know how? when i click submit then file backup.sql will be restored in database, help please.. <? if(isset($submit)){ $backup = $_POST['backup']; $sql = // what should i do in here?? $qry = mysql_query($sql) or die(mysql_error()); if($qry){ echo "Database has been restored"; } } ?> <form action='' method='post'> Please input your backup name sql : <input type=text name=backup> <input type='submit' value=submit> </form> Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 i have read it once sorry i forgot but for sure there is what it does is read the file and load in db Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 ok got it LOAD DATA INFILE that will do Quote Link to comment Share on other sites More sharing options...
ky0shiro Posted July 6, 2007 Author Share Posted July 6, 2007 Just like this ?? <? if(isset($submit)){ $backup = $_POST['backup']; $sql = LOAD DATA INFILE; $qry = mysql_query($sql) or die(mysql_error()); if($qry){ echo "Database has been restored"; } } ?> <form action='' method='post'> Please input your backup name sql : <input type=text name=backup> <input type='submit' value=submit> </form> Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 http://www.mysql.com/news-and-events/newsletter/2002-05/a0000000012.html Quote Link to comment Share on other sites More sharing options...
ky0shiro Posted July 6, 2007 Author Share Posted July 6, 2007 Hi, sorry i still don't undestand here is my code, i dont know where is the false? <? $DBhostname = $_POST['DBhostname']; $DBuserName = $_POST['DBuserName']; $DBpassword = $_POST['DBpassword']; $Database = $_POST['Database']; $conn = mysql_connect ($DBhostname, $DBuserName, $DBpassword) or die('Connection Failed!'); $file = 'backup.sql'; mysql_query("LOAD DATA LOCAL INFILE '$file' INTO $Database"); ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 that should work sendme the error or try this mysql_query("LOAD DATA INFILE $file INTO $Database"); $Database?? supply db name Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 mysql_query("LOAD DATA LOCAL INFILE 'd:/data/data.txt' INTO TABLE maindata"); or maybe the location is the prob see ^^ Quote Link to comment Share on other sites More sharing options...
ky0shiro Posted July 6, 2007 Author Share Posted July 6, 2007 here is my code : <? $DBhostname = localhost; $DBuserName = root; $DBpassword = ''; $Database = 'users'; $conn = mysql_connect ($DBhostname, $DBuserName, $DBpassword) or die('Connection Failed!'); $file = 'sql.sql'; mysql_query("LOAD DATA INFILE '$file' INTO $Database") or die(mysql_error()); ?> Here is the error that i got : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'users' at line 1 Here is the content of file sql.sql : create database if not exists `users`; USE `users`; /*Table structure for table `category` */ DROP TABLE IF EXISTS `category`; CREATE TABLE `category` ( `cat_id` tinyint(4) NOT NULL default '0', `cat_name` varchar(20) NOT NULL default '' ) ENGINE=MyISAM DEFAULT CHARSET=latin1; /*Data for the table `category` */ insert into `category`(`cat_id`,`cat_name`) values (1,'news'),(2,'events'); Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 create database if not exists `users`; /*Table structure for table `category` */ DROP TABLE IF EXISTS `category`; simply use dbname;//put the db to be use try to remove first to know your error Quote Link to comment Share on other sites More sharing options...
ky0shiro Posted July 6, 2007 Author Share Posted July 6, 2007 im sorry, i dont understand what do you mean? simply use dbname;//put the db to be use ?? try to remove first to know your error <-- what i should remove? sorry, i really2 dont understand what do you mean.. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 DROP TABLE IF EXISTS `category`; CREATE TABLE `category` ( `cat_id` tinyint(4) NOT NULL default '0', `cat_name` varchar(20) NOT NULL default '' ) ENGINE=MyISAM DEFAULT CHARSET=latin1; insert into `category`(`cat_id`,`cat_name`) values (1,'news'),(2,'events'); remove the comment try that first and tell me the error you see it reds the file now the prob is the sql syntax in the file Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.