Chintan_chiku Chintan_chiku - 1 month ago 14
MySQL Question

Yii how to check if query execution failed

I M Using YII to develop web application

i want to check if query executed successfully or not

$data = Yii::app()->db->createCommand($SQL);
$result = $data->queryAll();

if(count($result) == 0)
{
throw new SoapFault('Sender', 'Unable to get display information.');
}


if code will execute if select query return no result-set. but i want to check if query executed successfully or not. based on that i want to throw exception. then if query executed successfully and returned no result-set then some other exception.

how to do this ? any suggestions ?

Answer
try {
    $result = $data->queryAll();
} catch (Exception $ex) {
    echo 'Query failed' , $ex->getMessage();
}
Comments