• Resolved lopxen

    (@lopxen)


    Hi,

    I am running a “SELECT” sentence via wpdb->get_results($sql) or die (mysql_error()).

    When the sentece produces results, no problem, but if there result is “empty”, the “die()” stops de execution, but it the mysql_error() shows nothing. Furthermore, mysql_errno() is 0.

    The question is, if there is no sql error, why die() stops the execution?

    I been searching for hours in the internete, but nothing. I am getting completely crazy!!!

    Thanks!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The big question is… Why are you using or die() in the first place? I’m guessing that you’re trying to handle erorrs? if so there’s better ways to do it then that.

    Thread Starter lopxen

    (@lopxen)

    Hi Catacausic,

    Yes, i am handling error. I am using other ways to do it, but i need to understand this because it impacts in many places in may code.

    Thanks!

    catacaustic

    (@catacaustic)

    You should be using the built-in error handling, as that will help you out, and it won’t create the same issues that you’re getting now.

    The basics behind it is that the or die () part is looking for a true result from the query, and an empty array equates to false so the die() is triggered. Taken directly from the PHP manual:

    When converting to boolean, the following values are considered FALSE:

    the boolean FALSE itself
    the integer 0 (zero)
    the float 0.0 (zero)
    the empty string, and the string “0”
    an array with zero elements
    an object with zero member variables (PHP 4 only)
    the special type NULL (including unset variables)
    SimpleXML objects created from empty tags

    http://codex.ww.wp.xz.cn/Class_Reference/wpdb#Show_and_Hide_SQL_Errors

    Some other reasons on why you shouldn’t do it the way that you’re doing it now:
    http://www.phpfreaks.com/blog/or-die-must-die
    http://stackoverflow.com/questions/432454/how-does-do-something-or-die-work-in-php

    Thread Starter lopxen

    (@lopxen)

    THANKS!!!!
    That what is was looking for…the reason!!. I am going to review your post carefuly!!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Empty wpdb->get_resuts die de execution’ is closed to new replies.