Jump to content

Import data from file.sql


ky0shiro

Recommended Posts

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>

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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");

?>

 

 

Link to comment
Share on other sites

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');

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.