0

How can i import *.sql in mysql database using php
how can i do this please help me to fix this issue thanks
here's my code :

if (mysql_connect('localhost', 'root', ''))
{
    print_success("Connection à la base de donnée réussie.")   ;
}
else print_error(mysql_error()) ; 

mysql_query(" CREATE SCHEMA IF NOT EXISTS ".$_SESSION['dbname']." DEFAULT CHARACTER SET utf8 COLLATE utf8_swedish_ci ; ") or print_error(mysql_error()) ; 


// Création du User/Password
$_SESSION['dbuser'] = "user".$_SESSION['subdomain'];
$_SESSION['dbpassword'] = substr(md5($_SESSION['subdomain'].$_SESSION['subdomain']),0,12);

@mysql_query(" DROP USER ".$_SESSION['dbuser']." ; ") ;  
mysql_query(" CREATE USER ".$_SESSION['dbuser']." IDENTIFIED BY '".$_SESSION['dbpassword']."'; ") or print_error(mysql_error()) ; 

if(WEBSERVER) mysql_query(" GRANT ALL PRIVILEGES ON ".$_SESSION['dbname'].".* TO '".$_SESSION['dbuser']."'@'localhost' IDENTIFIED BY '".$_SESSION['dbpassword']."' ; ") or print_error(mysql_error()) ; 
else mysql_query(" GRANT ALL PRIVILEGES ON ".$_SESSION['dbname'].".* TO '".$_SESSION['dbuser']."'@'10.0.66.%' IDENTIFIED BY '".$_SESSION['dbpassword']."' ; ") or print_error(mysql_error()) ;

$sqlFile = "Database.sql";
$command='mysql -h localhost -u root ".$_SESSION['dbname']." < ' .$sqlFile;

It create an empty database, and dump the sql file at the current database which duplicate items!

0

1 Answer 1

0

In your code, your $_SESSION['dbname'] should be set to the database you want to execute the dump on.

However, assuming this is correct (which I do assume, because the script creates the empty DB), please check your .sql file to make sure that it isn't creating or using a database (USE xyz or CREATE DATABASE xyz) inside that file.

As an edit, I would like to request the Database.sql file to confirm that it is not switching DBs. Of course, please edit out sensitive information if you do fulfill this request.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.