Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel/Lumen cannot call MySQL procedure with CURSOR #27951

Closed
maxsky opened this issue Mar 21, 2019 · 12 comments
Closed

Laravel/Lumen cannot call MySQL procedure with CURSOR #27951

maxsky opened this issue Mar 21, 2019 · 12 comments

Comments

@maxsky
Copy link
Contributor

maxsky commented Mar 21, 2019

  • Laravel Version: 5.5.45
  • Lumen Version: 5.7.8
  • PHP Version: 7.1.26
  • Database Driver & Version: PDO_MySQL & mysqlnd 5.0.12-dev - 20150407

Description:

I tried to call a procedure in Laravel/Lumen, but always return this exception:

Packets out of order. Expected 1 received 10. Packet size=40

I found the problem with a PDO attribute PDO::ATTR_EMULATE_PREPARES.

If this attribute set true, it's run success. But in the framework, this default value is false.

Certainly, this attribute safer than true, and my procedure used with CURSOR.

If I used a procedure without CURSOR, and PDO::ATTR_EMULATE_PREPARES = false, its run success too.

Maybe this is client driver problem? T_T...

Steps To Reproduce:

// Add this can be success:
// DB::getPdo()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
DB::select('CALL pro_test(?, ?)', [NULL, 0]);
@maxsky maxsky changed the title MySQL cannot call procedure with CURSOR Laravel/Lumen cannot call MySQL procedure with CURSOR Mar 21, 2019
@driesvints
Copy link
Member

I'll need someone who knows more about cursors and mysql procedures to verify this.

Also: this Lumen version isn't supported anymore. Can you try to upgrade to 5.8 and see if the problem persists?

@staudenmeir
Copy link
Contributor

Please provide a simple procedure to reproduce the issue.

@eis3nhorn
Copy link

@driesvints Just tried on latest version of lumen (5.8), getting same error. Details on cursors here: http://www.mysqltutorial.org/mysql-cursor/ Its essentially a way to do FOR loops in sql

@eis3nhorn
Copy link

Example Stored Procedure that reproduces the issue:
DELIMITER $$
CREATE PROCEDURE sp_test(
)
BEGIN

DECLARE s VARCHAR(10);
DECLARE done INT DEFAULT FALSE;
DECLARE cur1 CURSOR FOR SELECT '1';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO s;
IF done THEN
LEAVE read_loop;
END IF;
END LOOP;
CLOSE cur1;

SELECT 1;

END$$
DELIMITER ;

@eis3nhorn
Copy link

Also note the cursor in this example doesn't even do anything, just its mere presence is enough.

@maxsky
Copy link
Contributor Author

maxsky commented Mar 21, 2019

I'll need someone who knows more about cursors and mysql procedures to verify this.

Also: this Lumen version isn't supported anymore. Can you try to upgrade to 5.8 and see if the problem persists?

I tried write native code with PDO, and set PDO::ATTR_EMULATE_PREPARES = false, return same problem. I originally found this problem in the Lumen framework, so I think this problem has nothing to do with the framework version or even the framework.


I used Wireshark catch MySQL data packets, it's so strange and looks like character be changed at response.

@staudenmeir
Copy link
Contributor

This is definitely a MySQL/PDO issue and not related to Laravel.

@maxsky
Copy link
Contributor Author

maxsky commented Mar 22, 2019

@staudenmeir Thx, I think so, but I still have not any solution. ToT...

@techouse
Copy link

Yea, this looks like a driver issue not Laravel per se.

@driesvints
Copy link
Member

Since everyone seems to agree that this isn't an issue with the framework I'm going to have to close this one off. Maybe a bug report to the PHP core is wanted? https://bugs.php.net

@madleech
Copy link

PHP bug, first reported in 2013, appears to affect all PHP versions. https://bugs.php.net/bug.php?id=64638

@maxsky
Copy link
Contributor Author

maxsky commented Jul 2, 2019

@madleech Yes, I found this...I think this bug is very bad, it has been so many years.

mfn added a commit to mfn/laravel-framework that referenced this issue Jul 3, 2019
Laravel will miss-behave in multiple ways with MySQL and PgSQL as documented in various issues and even PRs, because people try to get a fix in but _the_ recommendation right now is to *not* use it.

I figured it might save everyones time if ppl fill this out upfront because it's often takes some forth and back until users mention this.

See:
- laravel#29023
- laravel#23850
- laravel#25818
- laravel#27951
- laravel#28149
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants