Error when connecting to DB with Kirby toolkit

Hi, I have problem with my DB connection. It’s weird because when I am using localhost server, everything works just fine. I am using the same DB as on production server with same credentials. But on production server, I am getting error when I am trying to connect to database:

SQLSTATE[HY000] [2027] Malformed packet

This error is thrown by the SQL server, not directly by Kirby. I just searched for the error code and message and it seems like this could either be caused by a MySQL bug or by the php.ini configuration.

Since it works with the same server locally, I’d check the PHP configuration first. If you search for the error message, you can find out more about this.

Thank you for your suggestions. I contacted hosting provider but they are still trying to figure out how to fix it on their side. I tried some changes but always ended up with error. Last one was this:

SQLSTATE[HY000] [2005] Unknown MySQL server host

Which was funny, because it still worked well on local server. But finally I found solution which works. I had to specify port as separate variable. Funny thing is that both solution works well on local server but only second is working on production. Maybe some problem with DNS, but I am not sure. They are not using default port for DB connection.

Just for info, this works well on local server but not on production (connection setup through config and ):

c::set('db.host', 'mydbhost:3312');
c::set('db.user', 'mydbuser');
c::set('db.password', 'mypassword');
c::set('db.name', 'mydb');

This works everywhere:

$db = new Database(array(
  'host'     => 'mydbhost',
  'port'      => '3312',
  'database' => 'mydb',
  'user'     => 'mydbuser',
  'password' => 'mypassword'
));

Question is, is there any way how to specify port in config? I would prefer first option and would like to have all setup info in my config file. But maybe hosting provider will find some solution on their side.

You could try this in your config file:

db::connect(array(
  'host'     => 'mydbhost',
  'port'      => '3312',
  'database' => 'mydb',
  'user'     => 'mydbuser',
  'password' => 'mypassword'
));

It should connect once and then store the connection in memory for later use. Disadvantage: Kirby will connect to the DB on every page load, even if you don’t need the database connection after all.

Unfortunately, adding a config variable for the port is not a longterm solution either. There are also other params like socket and other DB systems might require their own params. Maybe we should replace the DB config options with one called db.params that can be set to an array of params? Just thinking out loud.