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
https://forums.phpfreaks.com/topic/58636-import-data-from-filesql/
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>

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

?>

 

 

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

 

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.