SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP gurus helped , needed, how to suppress database error

    hi,

    If i try to hit the database with invalid sql I get this error. I was told if that error occurs , suppress it ..how can i do that, is it even possible?





    Fatal error: Uncaught exception 'InvalidSQLQueryException' with message 'Invalid SQL: SELECT * FROM `romance_zip` WHERE zip3 = '222' and site_id is NULL <b> 1054:Unknown column 'zip3' in 'where clause' .</b>' in /home/irfan/projects/sitemanager2/lib/helpers/base.php:119 Stack trace: #0 /home/irfan/projects/sitemanager2/lib/helpers/record_base.php(331): Base::query('SELECT * FROM `...', '') #1 /home/irfan/projects/sitemanager2/lib/helpers/record_base.php(297): RecordBase::find_by_sql('RomanceZip', 'SELECT * FROM `...', '') #2 /home/irfan/projects/sitemanager2/sites/extendedwarranty1/trunk/controllers/extendedwarranty1_controller.php(125): RecordBase::find_all('RomanceZip', 'zip3 = '222' an...') #3 /home/irfan/projects/sitemanager2/sites/extendedwarranty1/trunk/controllers/extendedwarranty1_controller.php(17): Extendedwarranty1Controller->get_provider('222222') #4 /home/irfan/projects/sitemanager2/app/common/controllers/basic_site_controller.php(189): Extendedwarranty1Controller->process_step1() #5 /home/irfan/projects/ in /home/irfan/projects/sitemanager2/lib/helpers/base.php on line 119

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    catch the exception in a try {} catch() block
    http://www.php.net/try

    in addition, you shouldnt even be displaying php generated errors on a production site(although its useful when coding/debugging)

    turn off the display_errors setting in php.ini, .htaccess, or with ini_set() when a site is live.
    http://www.php.net/manual/en/configuration.changes.php

  3. #3
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by clamcrusher
    turn off the display_errors setting in php.ini, .htaccess, or with ini_set() when a site is live.


    what i do is using a debug flag, ie during coding debug flag is set to ON and error_messages is set to E_ALL
    When going online, debug flag is set to OFF and error_messages is set to 0 using my own error messages just providing common messages and not beeing too specific.
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am tryig like this my function where error take place is

    PHP Code:
    public static function find_all($class_name$where="1"$args="")  
        {  
            
    // check to make sure that the class passed actually exists.  
            
    if (!class_exists($class_name))  
                throw new 
    NonExistantClassException('The class specified for RecordBase::find_all() does not exist.');  
          
            
    // extract all of the classes variables to get its primary key.  
            
    extract(get_class_vars($class_name));  
              
            
    // build the sql statement used to get the desired rows.  
            
    $sql "SELECT * FROM `{$table_name}` WHERE {$where} {$args['group_by']} {$args['order_by']} {$args['having']} {$args['limit']}";  
              
            
    // calls the method to get the records we are searching for.  
            
    return self::find_by_sql($class_name$sql$args);  
        } 
    I am calling it like this

    PHP Code:
    try{ 
    $this->sites Buyer::find_all("Buyer"); 
    }     
    catch (
    NonExistantClassException $e )  
    {  
       
    // mail("you@site.com", "Query Error", $e->message);  
        
    die ( "I'm afraid there was an error with the database server, please contact the help desk.");  

    but stil i get this error ,

    Fatal error: Uncaught exception 'NonExistantClassException' with message 'The class specified for RecordBase::find_all() does not exist.' in /home/irfan/projects/sitemanager2/lib/helpers/record_base.php:298 Stack trace: #0 /home/irfan/projects/sitemanager2/app/common/controllers/basic_site_controller.php(39): RecordBase::find_all('Site', 'url = 'extended...') #1 /home/irfan/projects/sitemanager2/public/index.php(107): BasicSiteController->__construct() #2 {main} thrown in /home/irfan/projects/sitemanager2/lib/helpers/record_base.php on line 298



    what am i doing wrong here?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •