[TriLUG] Stuck -- PHP MySQL ( 22nd )

Brian McCullough via TriLUG trilug at trilug.org
Mon Aug 22 15:39:30 EDT 2022


Well, I seem to have another one.


I am trying to write a very simple PHP command line program, using PDO,
to read a database on my machine.  Easy, right?   No.

I have a local 5.6.10 database in my machine, living in
/usr/local/mysql, which wants to put its socket file in /tmp.

Running mysql at the command line, everything works.  Running my PHP
program, it reports, using the same credentials, "localhost" and port
number, "Connection refused."

OK, so maybe PHP and MySQL are looking at different places for the
socket.  After some research, I explicitly specified
"/var/run/mysqld/mysqld.sock" in my.cnf ( and
/etc/mysql/mysqld.conf.d/mysqld.conf ), and "mysql" works correctly.

The PHP program still refuses to connect.  I went in to php.ini and
added the socket address to both the mysqli and pdo_mysql sections.  No
change in result.

I also happen to have a Docker container running a different MySQL
database ( under Laravel Sail ), using a different port number, so that
I don't conflict with the "local" one.  Using "mysql -h docker-address
-P 3360 -u sail -p" didn't work, because ( among other things ) "mysql"
is, of course, the local ( 5.6.10 version ) while the Docker version is
8.0.30.

The PHP program fails to connect there, but I don't have a good working
test, although "telnet docker-address 3360" and "telnet localhost 3306"
both give reasonable results.


That should cover all of my digging and experiments.  Does anybody have
any bright ideas?


Thank you,
Brian



More information about the TriLUG mailing list