Showing the stored procedure error to the user

Hello,

This is my first post :)

I am new to the PHP world and Yii2. I do have some DB stored procedures and other programming languages skills.

I am not using Active Record. I am trying to code all (if possible) business logic in MySQL database and the data is accessed via stored procedures, only. The stored procedure may raise either database related errors or business logic errors.

Few examples:

[sql]

DECLARE ERR_FOREIGN_KEY CONDITION FOR 1452;

DECLARE EXIT HANDLER FOR ERR_FOREIGN_KEY

RESIGNAL SET MESSAGE_TEXT = ‘… my error text here …’;

DECLARE EXIT HANDLER FOR ERR_DUPLICATE_INVOICE

RESIGNAL SET MESSAGE_TEXT = ‘… my error text here …’;

IF ROW_COUNT() = 0 THEN

SIGNAL SQLSTATE ‘45000’ SET MESSAGE_TEXT = ‘… my error text here …’;

END IF;[/sql]

My question is:

What is the best approach to show the stored procedure error to the user?

Thank you.

I am looking for the same thing only in Yii1. I hope someone can help.