0

I am trying to catch error mechanism with php but it does not return $dataTable on exceptions. if pg_quey gives error, it prints error message on screen.

    try{
        $queryResult = pg_query($this->connection, $query_string);


        while($row = pg_fetch_assoc($queryResult)){
            $dataTable[] = $row;
        }

        return $dataTable[0];            

    }catch (Exception $ex){
        return $dataTable;
    }
barteloma
  • 6,403
  • 14
  • 79
  • 173
  • 1
    Maybe because that method doesn't throw an exception on error? What does the error message say? Is it `Uncaught exception` or something else? – N.B. Sep 10 '14 at 14:05
  • Are you setting `$dataTable` somewhere? If it's not set, it can't return it. – BA_Webimax Sep 10 '14 at 14:05
  • 1
    According to [pg_query manual](http://php.net/manual/en/function.pg-query.php) it doesn't throw an exception, rather returns `false` if something goes wrong. –  Sep 10 '14 at 14:08
  • on catch it can't return $dataTable if you don't set it before. Try to return $ex – budamivardi Sep 10 '14 at 14:51

0 Answers0