Assign a variable to SQL errors

Hello, I am returning sql errors in my application, such as:


CDbCommand failed to execute the SQL statement: SQLSTATE [23000]: Integrity constraint violation: 1452 Can not add or update a child row: a foreign key constraint fails…"

I wonder if there is any way to get this "error string" that comes from the database to assign a variable for example.

Thank you!


You could use a try/catch block to get the exception message and assign it to a variable within the catch.

Something like:

try {



} catch (CDBException $e) {

    $this->myvar = $e->getMessage();


Thank’s! ;)