Hi i'm developing the panel where admin can import the csv file directly to mysql database. But I'm getting the error.
My code is
<?php
//ENTER THE RELEVANT INFO BELOW
$mysqlDatabaseName ='bilmos';
$mysqlUserName ='root';
$mysqlPassword ='23nbhfi9';
$mysqlHostName ='localhost';
$mysqlImportFilename ='backup_26dec.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> File is uploaded to Mysql<b>' .$mysqlDatabaseName .'</b>';
break;
case 1:
echo 'Unable to upload, Try again or check if same file exists in the folder or not:<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;
}
?>
Output as error:-
Unable to upload, Try again or check if same file exists in the folder or not:
MySQL Database Name: bilmos
MySQL User Name: root
MySQL Host Name: localhost
MySQL Import Filename: backup_26dec.sql
Please tell me where i'm doing wrong?
1 Answer(s)