I try to capture the error output.
<?php
$output = array();
$command = <<<END
mysql -h$host -u$user --password='$pass' --execute="create database $name;" 2>&1
END;
exec($command, $output, $code);
?>
But this query returns an error in the terminal: "database already exists".
When I remove 2>&1
$command = <<<END
mysql -h$host -u$user --password='$pass' --execute="create database $name;"
END;
exec($command, $output, $code);
How can I get the correct $output and $code value?
Had the same problem, except that I was importing a .sql file instead of using --execute
It worked after I added 2>&1 and using double quotes instead of singles.
exec("mysql -h $host -u $user -p$pass my_db < \"faulty_sql.sql\" 2>&1",$output);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With