0

I've read carefully the reply to this question How does “do something OR DIE()” work in PHP? but yet I can not use the OR DIE() properly into my script using oop like in the following snippet of code

class UsingMysql {
    ...
    function QueryDB ($query_string) {
         $resource = mysql_query ($query_string);
         return $resource;
     }
}
...

$mysql = new UsingMysql();
...
function get_director() {
    global $mysql;
    $query_d = ...
    $result_d = $mysql->QueryDB($query_d) or die (mysql_error());
}
...
get_director();

My script works fine only when I remove the OR DIE construct from the statement. Why?

Community
  • 1
  • 1
  • 1
    If your "do something" returns a falsey result, then the "or die()" will be executed as well; if your "do something" returns a truthy result, then the "or die()" will not be executed – Mark Baker Mar 22 '15 at 12:16
  • @Mark Baker, I'm using `SELECT` in the query for MySQL, is the string returned considered like a logical value? – Tetravalente Mar 22 '15 at 12:31
  • Any value can generally be tested for truthiness (e.g. integer or float 0/0.0 is false): in your case, a mysql_query will return false if the query execution fails/errors – Mark Baker Mar 22 '15 at 12:37

0 Answers0