0

i want to import my backup database(.sql file) into mysql using php script. i have given the following code where case 1 section works. but i need to execute case 0 section. what the problem in my code please help me anyone.

<?php
//ENTER THE RELEVANT INFO BELOW
$mysqlDatabaseName ='online_admission_form';
$mysqlUserName ='root';
$mysqlPassword ='';
$mysqlHostName ='localhost';
$mysqlImportFilename ='db-backup-1360387884-770ac5920c7155e73215540b30ed1c18.sql';

//DONT EDIT BELOW THIS LINE
//Export the database and output the status to the page
$command='mysql -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' < ' .$mysqlImportFilename;
exec($command,$output=array(),$worked);
switch($worked){
    case 0:
        echo 'Import file <b>' .$mysqlImportFilename .'</b> successfully imported to database <b>' .$mysqlDatabaseName .'</b>';
        break;
    case 1:
        echo 'There was an error during import. Please make sure the import file is saved in the same folder as this script and check your values:<br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' .$mysqlDatabaseName .'</b></td></tr><tr><td>MySQL User Name:</td><td><b>' .$mysqlUserName .'</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' .$mysqlHostName .'</b></td></tr><tr><td>MySQL Import Filename:</td><td><b>' .$mysqlImportFilename .'</b></td></tr></table>';
        break;
}
?>  
4
Contributors
3
Replies
33
Views
4 Years
Discussion Span
Last Post by diafol
0

What would you like to do when case 0? I think case 0 is when the import went without any problems. Then you don't have to do anything else apart from letting users know (which has already been done).

0

This code is not work and gives and error:

There was an error during import. Please make sure the import file is saved in the same folder as this script and check your values:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.