Insert data to MySql DB and display if insertion is success or failure

前端 未结 5 1890
执念已碎
执念已碎 2020-12-10 05:09

I am inserting data to a MySQL DB, In case if the insertion fails i need to give an appropriate error message indicating so. According to my code below i will be Echo-

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 06:04

    After INSERT query you can use ROW_COUNT() to check for successful insert operation as:

    SELECT IF(ROW_COUNT() = 1,  "Insert Success", "Insert Failed") As status;
    

提交回复
热议问题