>Hi, I am trying to import some tables from a dump file into a MySQL database
>from a php web page. What is the best way to do this without using backticks
>(fpassthru, system, exec or something else) and test for success or failure?
>I tried the following and while it works, my test for success or failure
>always produces a "Success" even when I change something to make it fail. I
>thought system() outputs the last line of the command on success and FALSE
>on failure. Any examples appreciated.

The FALSE on failure is if PHP completely fails to execute the command at
all.  This is a rather rare condition.

PHP is quite happy to execute commands that "fail" (whatever that means) and
return the last line of their output which may, or may not, contain an error
message you could detect, though, and as far as PHP is concerned, it did not
fail to execute the command.  That your command didn't do what you wanted,
or that the command itself failed, is not a "failure" on the part of PHP, if
you see what I mean.

However, you may want to use exec() and get the full output, as well as the
OS error code, if any, returned by MySQL and then you'd know for sure what

>$status = system("mysql -umyuserid -pmypassword mydbname <
>if($status == 'FALSE'){
>echo 'Failed';
>} else {
>echo 'Success';

Like Music?  http://l-i-e.com/artists.htm
Off-Topic:  What is the moral equivalent of 'cat' in Windows?

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to