سؤال

I'm trying to convert some PHP code from Mysqli to PDO, and I need to be able to set a default host for PDO MySQL connections (outside of my application code).

With Mysqli, I could do this with the php.ini setting:

mysqli.default_host = ip.of.mysql.server

And then connect with:

$link = mysqli_connect(null,  USERNAME,  PASSWORD, DATABASE);

It's worked beautifully for us.


The equivalent code for PDO:

$link = new PDO('mysql:dbname=' . DATABASE, USERNAME, PASSWORD);

Doesn't work the same way. It works as long as my MySQL server is on localhost. It isn't. I have a separate machine hosting my MySQL server.

Is there an equivalent php.ini setting that could accomplish what I need for PDO? The closest thing I've found is a pdo_mysql.default_socket setting, but I don't think that will do it.

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top