Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

PHP why doesn't catch error

Codes here !

Moderators: macek, egami, gesf

PHP why doesn't catch error

Postby Gonzalos » Thu Jun 28, 2012 10:57 pm

Hello I am trying to catch any error that can ocure when executes $query, but It doesn't catch the error, It just show the error on the screen, Why is that?
I am using mysqli

Code: Select all
function insertField ($query){
      try {
         $stmnt = $this->mySqli->prepare($query);
         $result = $stmnt->execute();
         //$stmnt->close();
         if (!$result)
         {
            return false;
         } else {
            return true;
         }
      } catch (Exception $e) {
          echo 'Exception: ',  var_dump($e->getMessage()), "\n";
         echo $query;
      }
   }



Thanks
Gonzalos
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed May 30, 2012 6:39 am

Re: PHP why doesn't catch error

Postby johnj » Fri Jun 29, 2012 1:02 am

Where are you throwing your exception?
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHP why doesn't catch error

Postby Gonzalos » Fri Jun 29, 2012 5:24 am

When I call the function I send a $query which is not valid

Thanks
Gonzalos
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed May 30, 2012 6:39 am

Re: PHP why doesn't catch error

Postby johnj » Wed Jul 04, 2012 8:34 am

please read about exceptions in php from php.net
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.