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

SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders #18

Open
stebogit opened this issue Nov 2, 2017 · 4 comments

Comments

@stebogit
Copy link

stebogit commented Nov 2, 2017

Hey @yadakhov I guess I pushed too hard insert-on-duplicate-key, cause apparently I hit the limit of MySQL. 😅
I'm just posting this here mainly for maybe somebody else who could get carried away with fast bulk insert/updates like me.

I tried to insert ~5,800 rows of 32 columns at once and I got the above error. It seems it's due to the place holders limit of MySQL.

Don't know if you want to, but basically I believe it's possible to fix this limiting the length of the inline $data array generating the SQL statement. You could split the array and iterate through it in slots of less than ~65,000 placeholders, or maybe simply raise an Exception for "too much data". It seems in fact Eloquent (v5.5 in my case) somehow fails to raise an appropriate Exception and keeps trying forever.

BTW I fixed the issue limiting my data to ~2,000 rows and it works great, super fast! 🚀

@yadakhov
Copy link
Owner

yadakhov commented Nov 3, 2017

Thanks for submitting your error.

I will add an exception telling users to array chunks their large array if it is over the mysql placeholder limits of 65,535.

@Slman42
Copy link

Slman42 commented Dec 11, 2018

SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders

Help me to Solve this please

@yadakhov
Copy link
Owner

You can break your data into smaller chunks. Something like:

// break data into max size of 200
$chunks = array_chunk($data, 200);

foreach ($chunks as $chunk) {
    // Do insert here
}

@Slman42
Copy link

Slman42 commented Dec 13, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants