3

I am using paris orm to develop a web application. I am adding data to the database and it fails, when i use a try catch block to catch the error it doesnt work.

My configurations are

ORM::configure('mysql:host='.DB_HOST.';dbname='.DB_NAME);
ORM::configure('username',DB_USER);
ORM::configure('password',DB_PASSWORD);
ORM::configure('logging', true);
ORM::configure('error_mode', PDO::ERRMODE_EXCEPTION);

The insertion code

    try {
        $dataToStore                       = SessionData::create();
        $dataToStore->usession_sessioncode = $sessionCode;
        $dataToStore->usessdata_content    = $dataString;
        $dataToStore->save();

    } catch (PDOException $e) {
        echo $e->getMessage();
    } catch (Exception $e) {
        echo $e->getMessage();
    }

Really looked for a solution around but no one gives a clear answer. I want to be to catch the exception and know were the error is exactly.

emabusi
  • 51
  • 1
  • 7

1 Answers1

5

I'm guessing you are not writing use PDOException in your code, so maybe this will help:

try {
    $dataToStore                       = SessionData::create();
    $dataToStore->usession_sessioncode = $sessionCode;
    $dataToStore->usessdata_content    = $dataString;
    $dataToStore->save();

} catch (\PDOException $e) { //Added slash
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}
taxicala
  • 21,408
  • 7
  • 37
  • 66