I need to do a remote mysql connection from a server to another, using a standard PDO connection:
$db = new PDO('mysql:host=' . DATABASE_HOST . ';dbname=' . DATABASE_NAME . ';charset=utf8mb4', DATABASE_USER, DATABASE_PASSWORD, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
The problem is that this server has many IPs attached, both IPv4 and IPv6, and to avoid this error:
Host '2001:...' is not allowed to connect to this MySQL server in ...
I'd need to create many users in the target host, one for each IP... (or allow connections from any IP, which is unsafe)
Is it possible to specify which IP to use? For example with curl I can do that with:
curl_setopt($ch, CURLOPT_INTERFACE, '1.2.3.4');
But I didn't find any similar option for PDO.