Re: PHP mysqli is NOT trapping some errors when calling stored procedure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



After breaking my head against it for long and a lot googling, I found the
problem. It is closely related to
https://stackoverflow.com/questions/23196141/how-to-call-a-stored-procedure-within-another-stored-procedure-php-and-mysqli

Basically I had a case of PHP calling SP1, which in turn called SP2, and
everything working fine in a mysql client but breaking when called by PHP!

It turns out the problem is that SP2 was SELECTing a result set (ie. SELECT
*without* an INTO clause).

I re-wrote SP2 to necessarily do a SELECT INTO and that fixed the problem.

I think the ability to SELECT a result set without doing a SELECT INTO is a
crappy feature in MySQL. Lots of things crappy about MySQL (stored
functions, exception propagation up the stack, poor compilation and syntax
error pinpointing in stored procedures, bad concept of transaction
boundary, etc).

I think SELECTing a result set should be avoided at all costs.

Thanks,
Venkat



On Tue, Feb 12, 2019 at 10:01 PM Venkat Hariharan <vharihar@xxxxxxxxx>
wrote:

> Yes, I do have all reqd privs.
>
> In fact, as long as a duplicate key situation isnt encountered, I am able
> to invoke the stored proc from PHP alright and the record gets saved in the
> database.
>
> But when I try to re-do it using the same value (thereby I am expecting
> that 1062-DUPLICATE KEY error will be thrown and caught by PHP), I dont get
> any error from PHP!
>
> In mysql client or MySQL Workbench, I do see the error. when I invoke the
> stored proc.
>
> Thanks,
> Venkat
>
>
> On Tue, Feb 12, 2019 at 9:56 PM Aziz Saleh <azizsaleh@xxxxxxxxx> wrote:
>
>> Do you have sufficient privileges to execute stored procedures
>> (procs_priv) on PHP's end?
>>
>> On Tue, Feb 12, 2019 at 11:07 AM Venkat Hariharan <vharihar@xxxxxxxxx>
>> wrote:
>>
>>> Can you take a look at the issue that I've described at
>>>
>>> https://stackoverflow.com/questions/54643704/php-mysqli-is-not-trapping-some-errors-when-calling-stored-procedure
>>> and tell me what I am missing in my PHP code ?
>>>
>>> To summarize: I am calling a MySQL stored procedure from PHP that does
>>> some
>>> DMLs (using mysqli). But the problem is that PHP is not able to get
>>> intimated of some database error conditions raised by the stored proc
>>> (which I know are raised, bcoz they do get flagged when invoked from a
>>> mysql client)
>>>
>>> I've listed the relevant code fragments there. Am I not using mysqli
>>> correctly?
>>>
>>> Thanks,
>>> Venkat
>>>
>>

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux