DB encoding lost when reconnecting after error
-
I encountered the following error when the installer (Duplicator version: 0.5.28) was writing the first line in the installer-data.sql file to the target database:
**ERROR** database error write 'MySQL server has gone away' - [sql=/* DUPLICATOR MYSQL SCRIPT CREATED ON : 2015-08-18 02:47:41 */ SET FOREIGN...]
The installer continued to process the rest of the .sql file with no reported errors. However, the resultant website had strange characters, and the theme option settings was lost.
I traced the problem to the following code in installer.php:
//Check to make sure the connection is alive if (!empty($err)) { if (!mysqli_ping($dbh)) { mysqli_close($dbh); $dbh = DupUtil::db_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass'], $_POST['dbname'], $_POST['dbport'] ); } DUPX_Log::Info("**ERROR** database error write '{$err}' - [sql=" . substr($sql_result_file_data[$counter], 0, 75) . "...]"); $dbquery_errs++; //Buffer data to browser to keep connection open } else { if ($fcgi_buffer_count++ > $fcgi_buffer_pool) { $fcgi_buffer_count = 0; DupUtil::fcgi_flush(); } $dbquery_rows++; }
After reconnecting, the code does not set the session charset, so that the connection uses the server charset, which happens to be ‘latin1’. I managed to resolve the issue by adding the following code after the db_connect line:
@mysqli_query($dbh, "SET wait_timeout = {$GLOBALS['DB_MAX_TIME']}"); DupUtil::mysql_set_charset($dbh, $_POST['dbcharset'], $_POST['dbcollate']);
Can you please have a look at this, and to put in a longer term fix to set the appropriate db settings after the reconnection.
Thanks for a very useful plugin.
- The topic ‘DB encoding lost when reconnecting after error’ is closed to new replies.