is the code given is executable in Windows system? as it seems to be Linux commands
echo 'create database foo2' | mysql -uroot
mysqldump --skip-triggers -uroot foo | mysql -uroot foo2
EDITED I am executing the following code but I am not getting what I expect..
<?php
mysql_connect('localhost','root','********');
echo 'create database pranav_chk'. | mysql -u root
mysqldump --skip-triggers -u root pranav_test | mysql -u root pranav_chk;
?>
The code uses three command-line features:
echo
command|
symbol)mysql
command line clientAll three are available and work identically (to the degree they're used here) on Windows and on Linux, so the code is in fact portable.
Edit: The code needs to be run in the shell, you can't just put it into a PHP script. You have to use exec()
, something like this:
<?php
exec("echo 'create database foo2' | mysql -uroot");
exec("mysqldump --skip-triggers -uroot foo | mysql -uroot foo2");
?>
However, the mysql_connect()
call before won't do you any good, because it's only valid for the PHP script. You'll have to do authentication via the command line directly. Alternatively, you could use it and mysql_create_db()
to replace the first exec()
line.