interconnectit / Search-Replace-DB

This script was made to aid the process of migrating PHP and MySQL based websites. Works with most common CMSes.
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
GNU General Public License v3.0
3.99k stars 850 forks source link

[PHP8] SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'url' at row 1 #372

Open anasmoiz opened 2 years ago

anasmoiz commented 2 years ago

Hello,

When we are running the script with PHP 8.0 and we receive the following error.

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'url' at row 1

If we downgrade the version to PHP 7.3 or 7.4, it works perfectly I can see this issue was previously reported #354 as well but was closed without providing an actual solution.

Please note that this is not happening with every site hosted on PHP 8.0 but with a few. if you guys need any details or access to replicate this please let us know, we would really like to solve this issue with your team.

smissaertj commented 1 year ago

I can confirm the above.

How did you deal with this @anasmoiz ? Did you find a workaround of any kind?

alex-umani commented 9 months ago

It's not a solution, but I found a bit of a workaround. The problem is that in PHP 8, the PDO class switched from defaulting in SILENT mode to defaulting to EXCEPTION mode (https://php.watch/versions/8.0/PDO-default-errmode)

It doesn't solve the underlying problem (you are trying to insert invalid data to the database), but you can get it to ignore the errors and continue if you add the following line to srdb.class.php:

$params[ PDO::ATTR_ERRMODE ] = PDO::ERRMODE_SILENT;

Insert that around line 558, right before they explicitly set ERRMODE to EXCEPTION when the code is running in debug mode.

It's gotten the code running for me again. Hope it helps.