Select Page

I was migrating a website to another hostint.
It contained amongst other things a DataTables.net project in combination with ServerSide data (using ssp.class.php).

A quick database/file transfer was not enough.
In the logs I found a memory issue, so enhanced the memory in the php class calling the SSP class

ini_set("memory_limit","2048M");

Next there was this error.

DataTables warning: table id=table_2 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

json_encode returned nothing, though the corresponding sql statements were not empty.

Seemed it had something to do with encoding:
https://datatables.net/forums/discussion/21242/invalid-json-response-when-adding-some-utf-8-characters

I added a extra line inside the function sql_connect.

$db->exec(‘SET NAMES utf8’);

static function sql_connect ( $sql_details )
	{
		try {
			$db = @new PDO(
				"mysql:host={$sql_details['host']};dbname={$sql_details['db']}",
				$sql_details['user'],
				$sql_details['pass'],
				array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION )
			);
			//SB added 05/04/2021 because of empty json_encode return
			//https://datatables.net/forums/discussion/21242/invalid-json-response-when-adding-some-utf-8-characters
			$db->exec('SET NAMES utf8');
		}
		catch (PDOException $e) {
			self::fatal(
				"An error occurred while connecting to the database. ".
				"The error reported by the server was: ".$e->getMessage()
			);
		}

		return $db;
	}