mysql - mysqli signal to php error -


i have mysql stored procedure, in cases give signal error this:

    create definer=`root`@`localhost` procedure `insertaction`(in `employerid` int, in `storefromid` int, in `storetoid` int, in `storeid` int, in `productid` int, in `quantity` decimal(10,2), in `dualoperation` tinyint, in `inorout` tinyint)     language sql     not deterministic     contains sql     sql security definer     comment '' begin     start transaction;         select @lastactionid;         select @lasttransferid;         select @retval;         select sum(ad.quantity) @retval productin pri join actiondetails ad on ad.id=pri.id;         if dualoperation = 1                             if @retval>quantity                                             insert actions (employerid, storehouseid, `date`)                             values (employerid, storefromid, curdate());                         set @lastactionid = (select id actions order id desc limit 1);                         insert producttransfer (id, transfertype)                             values (@lastactionid, 0);                          insert actiondetails (id,productid, quantity)                             values (@lastactionid, productid, quantity);                          set @lasttransferid = (select id producttransfer order id desc limit 1);                         insert actions (employerid, storehouseid, `date`) values (employerid, storetoid, curdate());                         set @lastactionid = (select id actions order id desc limit 1);                         insert producttransfer (id, transfertype, parentid) values (@lastactionid, 1, @lasttransferid);                          insert actiondetails (id,productid, quantity)                             values (@lastactionid, productid, quantity);                     else                         signal sqlstate '45000'                     set message_text = 'not enough materials';             end if;         else                 insert actions (employerid, storehouseid, `date`)                     values (employerid, storeid, curdate());                 set @lastactionid = (select id actions order id desc limit 1);                 insert actiondetails (id, productid, quantity)                     values (@lastactionid, productid, quantity);                 if inorout = 0                                             insert productin (id, organizationid) values (@lastactionid, null);                     else                         if @retval>quantity                                                             insert productout (id, organizationid) values (@lastactionid, null);                             else                                 signal sqlstate '45000'                             set message_text = 'not enough materials';                     end if;                 end if;         end if;     commit; end 

when run code through mysql query seems working fine. gives signal of "not enough materials" if @retval<=quantity , no records inserted(works should be)... when call procedure php doesn't give error. none of rows inserted cant notification oppreration failed... here php code:

$mysqli->query("call `insertaction`('6', '1', '2', '0', '13', '431243241', '1', '0')"); 

the $mysqli->sqlstate gives 0000. how should understand procedure done or got signal?

so want is, if @retval<=quantity give php exception. , code prints "string" out:

try { $mysqli->query("call `insertaction`(6, 1, 2, 0, 13, 431243241, 1, 0)"); } catch (exception $e){     echo "string"; } 

mysqli not throw exceptions have old fashioned way

$result = $mysqli->query("call insertaction(6, 1, 2, 0, 13, 431243241, 1, 0)"); if ($result === false) {     echo $mysqli->error;     exit; } 

also 6th param decimal (10,2) not int number passing not fit 10,2 if rememebr correctly mean 8 digits before decimal place , 2 after, try number fits like

 $result = $mysqli->query("call insertaction(6, 1, 2, 0, 13, 4312432.41, 1, 0)"); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -