我想捕捉並顯示使用php的網頁上的查詢錯誤(以我選擇的方式)。因此,而不是下面從Postgresql捕獲錯誤到PHP
$result=pg_query($connection,$query);
if($result){
//success
}
else{
echo pg_last_error($connection);
}
我可以用這樣的錯誤代碼匹配或別的東西來實現的東西像
if(error equals duplicate value error){
echo "this value already exists";
}
else if(error equals different type error){
echo "You should enter wrong type for column blabla"
}
注意一個方法,我使用PostgreSQL
是的,你可以這樣做,但我不知道你在問什麼。 –
@AleksG 我不想使用pg_last_error函數。我想爲相應的錯誤手動編寫錯誤消息 – woryzower