Reputation: 643
I have two versions of MySQL, 5.6.20 and 5.7.25, installed on my server.
My php.ini
has
; php.ini
mysqli.default_socket=/opt/local/var/run/mysql57/mysqld.sock
I can edit tables for 5.7.25 using phpMyAdmin
, after which I see the updated records correctly (when using mysql
or phpMyAdmin
) for 5.7.25.
But when I put the following codes in a php file, I get version number 5.6.20:
$link = mysqli_connect("127.0.0.1", USERNAME, PASSWORD, "testdb");
echo mysqli_get_server_version($link); # shows 50620
What would be the problem? Thank you.
Upvotes: 0
Views: 876
Reputation: 1387
The issue is that 127.0.0.1
isn't actually the same as localhost
to MySQL. When you pass an IP address in the $host
parameter, the connection is forced over TCP/IP. Instead, pass "localhost"
and it should use the default UNIX socket instead of the network socket. (When using a default socket, I actually prefer to pass NULL
—which gets converted to localhost
—just to make it clearer that I'm expecting the connection to happen via socket.)
If that still isn't working, here are some troubleshooting steps you can take:
Place a phpinfo()
file and look under the MySQLi section with specific attention to the values of MYSQLI_SOCKET
and mysqli.default_socket
(both local and master values). It's possible that either this value is being overridden somewhere. If you see a different value in MYSQLI_SOCKET
, it's likely being influenced by the --with-mysqli-sock
compile-time flag.
You could run is echoing the output of mysqli_get_host_info($link)
(just to see if it's connecting via TCP or the socket).
You could also test by manually passing the correct socket in the 6th parameter ($socket
) of mysqli_connect()
. Again, this needs to be combined with the use of NULL
/localhost
for the $host
argument.
Upvotes: 3