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);
?>
- $output returns no value
- $code returns 0
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);
- $output returns no value
- $code returns 1
How can I get the correct $output and $code value?
mysql_create_db()
? – manatwork Nov 4 '11 at 9:58