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

String too long #52

Closed
schmidtl4 opened this issue Mar 22, 2024 · 4 comments
Closed

String too long #52

schmidtl4 opened this issue Mar 22, 2024 · 4 comments

Comments

@schmidtl4
Copy link

I just started getting this error (after upgrading to PHP 8.3.3):
Uncaught PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'session_data' at row 1 in C:\Apache24\htdocs\bluedots2\vendor\stefangabos\zebra_session\Zebra_Session.php:775

Zebra was working great for me in 7.4 and the same code that generated the error above, bid not generate an error when I was running PHP 7.4.

The database column definitions have not changed on my system.

What can be done to fix this?

@stefangabos
Copy link
Owner

stefangabos commented Mar 23, 2024

I haven't encountered this issue but it looks like something related to a db difference rather than it being related to PHP version difference.

Here it says that this happens when MySQL is in strict mode and it may be that on a previous environment it wasn't. The result in both cases is the same - data longer than the supported size is written to the db, BUT TRUNCATED TO FIT!, the only difference being that a warning is generated in strict mode, while the action is done silently when not in strict mode (and maybe this is why you had no errors previously)

If the data you have is really large you can change the session_data column type to MEDIUM BLOB or LONG BLOB depending on the size of the data you are planning to store.

Also, if you have to store so much data in the session a better solution would be to use redis or memcache instead of the session

@joebordes
Copy link

great answer

@stefangabos
Copy link
Owner

In my previous comment I forgot to mention that although data is indeed written to the db, it is truncated to fit the allowed size. I updated my previous comment

@schmidtl4
Copy link
Author

schmidtl4 commented Mar 24, 2024

Great response. Very helpful. Your instinct about the use of strict mode was spot on. It is possible that the amount of session data grew directly as a result of changing PHP versions, but it is more likely that the use of session data grew as the code features/functionality continued to expand after the change, Combined with the strict mode defaults for PHP 8, the error resulted. The net result is that changing the session_data column to MEDIUM BLOB fixed the issue. Thank you!

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