0

When I restore it using xampp shell command line its working but when I run it using php not working. Is this because of xampp configuration or something ?

shell script

mysql -u root -h localhost < Triggers.sql

here's my php code

$command='mysql -u root -p is2020_db < Triggers.sql';

exec($command);

1 Answers1

0

Running on PHP you should execute using shell_exec. Like this :

<?php
    $output = shell_exec('mysql -u root -p is2020_db < Triggers.sql');
    echo "<pre>$output</pre>";
?>

Another way

Your MySQL binaries should be somewhere under your XAMPP folder. Look for a /bin folder, and you'll find the mysql.exe client around. Let's assume it is in c:\xampp\mysql\bin, then you should fireup a command prompt in this folder.

That means, fire up "cmd", and type:

cd c:\xampp\mysql\bin
mysql.exe -u root -p is2020_db < Triggers.sql

Reference : How do I use MySQL through XAMPP?

Example on Windows

For those using a Windows OS, I was able to import a large mysqldump file into my local XAMPP installation using this command in cmd.exe:

C:\xampp\mysql\bin>mysql -u root -p is2020_db < /path/to/file/Triggers.sql

But you have to check if this command is allowed in your host and/or you have to allow this in your server.

Olavo Mello
  • 492
  • 2
  • 8