# PDO/MySQL connect broken for remote hosts

- Thread: https://externals.io/message/15091
- Original archive: https://news-web.php.net/php.internals/15091
- Started by Timm Friebe on 2005-02-18T10:16:34+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #15091 — Timm Friebe — 2005-02-18T10:16:34+00:00

URL: https://externals.io/message/15091#15091

Hi,
has anyone noticed PDO/MySQL will always try to connect locally
regardless of what I put in the host=... DSN part?

The statement:
  new PDO('mysql:host=php3.de', '****', '*******');

will only throw a PDOException:

Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2)' in /usr/home/thekid/pdo.php:2

This here fixes it:

Index: ext/pdo_mysql/mysql_driver.c
===================================================================
RCS file: /repository/php-src/ext/pdo_mysql/mysql_driver.c,v
retrieving revision 1.36
diff -u -r1.36 mysql_driver.c
--- ext/pdo_mysql/mysql_driver.c        13 Feb 2005 17:16:24 -0000
1.36
+++ ext/pdo_mysql/mysql_driver.c        18 Feb 2005 10:00:31 -0000
@@ -327,6 +327,7 @@
        if (vars[2].optval && !strcmp("localhost", vars[2].optval)) {
                unix_socket = vars[4].optval;  
        } else {
+               host = vars[2].optval;
                port = atoi(vars[3].optval); 
        }
        dbname = vars[1].optval;

-- 
Timm
If it ain't broken, it doesn't have enough features yet

---

## #15093 — Wez Furlong — 2005-02-18T15:11:45+00:00

URL: https://externals.io/message/15091#15093 · In reply to: #15091

Thanks; committed.

--Wez.



> Hi,
> has anyone noticed PDO/MySQL will always try to connect locally
> regardless of what I put in the host=... DSN part?
> 
> The statement:
>   new PDO('mysql:host=php3.de', '****', '*******');
> 
> will only throw a PDOException:
> 
> Fatal error: Uncaught exception 'PDOException' with message
> 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through
> socket '/tmp/mysql.sock' (2)' in /usr/home/thekid/pdo.php:2
> 
> This here fixes it:
> 
> Index: ext/pdo_mysql/mysql_driver.c
> ===================================================================
> RCS file: /repository/php-src/ext/pdo_mysql/mysql_driver.c,v
> retrieving revision 1.36
> diff -u -r1.36 mysql_driver.c
> --- ext/pdo_mysql/mysql_driver.c        13 Feb 2005 17:16:24 -0000
> 1.36
> +++ ext/pdo_mysql/mysql_driver.c        18 Feb 2005 10:00:31 -0000
> @@ -327,6 +327,7 @@
>         if (vars[2].optval && !strcmp("localhost", vars[2].optval)) {
>                 unix_socket = vars[4].optval;
>         } else {
> +               host = vars[2].optval;
>                 port = atoi(vars[3].optval);
>         }
>         dbname = vars[1].optval;
> 
> --
> Timm
> If it ain't broken, it doesn't have enough features yet
