Hi

Please consider the two code snippets. Can someone pls tell me which one is better and why?


Code:
$q = "insert into...";
mysql_query($q);

if(mysql_affected_rows()>0){
   $id = mysql_insert_id();
}else{
   $id = false;
}

if( ! $id ){
  echo 'Something went wrong: ' .  mysql_error();
}
AND

Code:
$q = "insert into...";

try{
  mysql_query($q);
}catch(Exception $e){
  echo echo 'Something went wrong: ' .  $e->getMessage();
}

From my understanding, the first one actually tells you if there was a problem in running the query.


Many thanks in advance