mysql class, error handling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • paranic

    mysql class, error handling

    Hi there

    i suppose we have the following class

    file database.php
    class InSQL
    {
    function query($query, $link_identifie r=null)
    {
    global $query_totals;

    $query_start = microtime(true) ;
    $return = mysql_query($qu ery, $link_identifie r);
    $query_stop = microtime(true) ;

    $query_totals[] = ($query_stop - $query_start);

    return $return;
    }
    }

    i call the query from another file
    file sample.php
    $result = InSQL::query($s ql, $localdb);

    when a mysql error occur php reports mysq error at file database.php
    line x.
    i whant without modifing the form of calling the queryies to display
    the correct error with the caller file and the caller line.

    one solution is to modify the calling line to $result =
    InSQL::query($s ql, $localdb, __FILE__, __LINE__);
    so if an error occur i will have the file and line where i called the
    query. but i dont whant to make the query calling line so complicated.

    the other solution is to change the query function as folows:
    function query($query, $link_identifie r=null, $file=__FILE__,
    $line=__LINE__)
    and call the query as always, but this reports the database.php file
    and the function query() line.


    is there any way to have correct error reporting without printing the
    query on the browser and without modifing the way i call the query
    function?


    Thanks in advance
    Nikos

  • Alvaro G. Vicario

    #2
    Re: mysql class, error handling

    *** paranic escribió/wrote (12 Jul 2006 03:37:29 -0700):
    is there any way to have correct error reporting without printing the
    query on the browser and without modifing the way i call the query
    function?
    You can use trigger_error() to raise custom errors. Then, you can write a
    custom error handling function and assign it with set_error_handl er(). This
    function allows you to do whatever you want with error messages: print on
    screen, log to file...

    PHP 5 has a new exception system. I haven't tried it but I suppose its
    similar to those in Java or JavaScript.

    --
    -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    ++ Mi sitio sobre programación web: http://bits.demogracia.com
    +- Mi web de humor con rayos UVA: http://www.demogracia.com
    --

    Comment

    • paranic

      #3
      Re: mysql class, error handling

      finaly i think i got my solution

      it is debug_backtrace ()
      and debug_print_bac ktrace()
      where it gives me where the error is originated and i can make my own
      custom error handling function for my sql class.

      thanks a lot.

      Comment

      Working...