PHP why doesn't catch error

Codes here !

Moderators: macek, egami, gesf

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

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

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 johnj » Fri Jun 29, 2012 1:02 am

Where are you throwing your exception?

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 Gonzalos » Fri Jun 29, 2012 5:24 am

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

Thanks

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 johnj » Wed Jul 04, 2012 8:34 am

please read about exceptions in php from php.net


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest