Using PHP to Connect to a Remote MySQL Server
Using PHP to Connect to a Remote MySQL Server
am 23.02.2006 20:17:53 von afrinspray
Everytime I attempt to connect to a remote mysql server, I get the
error about /tmp/mysql.sock not existing. I have the mysql client
installed on the php computer, but not the server. Is there a way to
tell php to use the client like "mysql -h[location of sql server]"
instead of going through the /tmp/mysql.sock socket?
Thanks,
Mike
Re: Using PHP to Connect to a Remote MySQL Server
am 23.02.2006 20:28:17 von afrinspray
BTW...
The connect string is not localhost, it's to the remote mysql server.
Re: Using PHP to Connect to a Remote MySQL Server
am 23.02.2006 20:41:27 von Steve
> Everytime I attempt to connect to a remote mysql server, I get the
> error about /tmp/mysql.sock not existing. I have the mysql client
> installed on the php computer, but not the server. Is there a way to
> tell php to use the client like "mysql -h[location of sql server]"
> instead of going through the /tmp/mysql.sock socket?
Please post a minimal functioning code sample that exhibits the
problem.
---
Steve
Re: Using PHP to Connect to a Remote MySQL Server
am 23.02.2006 22:22:43 von afrinspray
Ok,
$conn = mysql_connect($mysql_host, $username, $password, true);
Where
$mysql_host = another server (db.example.com)
$username = the username in the mysql database
$password = the password of the the user above
This all works if I use the command line mysql command with the -h
command for specifying a host. It's just through php that I get the
/tmp/mysql.sock does not exist error. I'm just confused why php would
require the socket if it's not connecting to mysql locally. Does PHP
require that the localhost have a mysql server installed even if I'm
connecting to a remote server?
Re: Using PHP to Connect to a Remote MySQL Server
am 23.02.2006 22:41:38 von afrinspray
Ok, I'm sorry... everything works fine. I made a simple mistake (I am
using this in an object, and I had $this->$mysql_host instead of
$this->mysql_host). I'm guessing if the host is blank, mysql_connect
tries the localhost?
Re: Using PHP to Connect to a Remote MySQL Server
am 23.02.2006 23:00:09 von Steve
> $conn = mysql_connect($mysql_host, $username, $password, true);
> Where
> $mysql_host = another server (db.example.com)
> $username = the username in the mysql database
> $password = the password of the the user above
> This all works if I use the command line mysql command with the -h
> command for specifying a host. It's just through php that I get the
> /tmp/mysql.sock does not exist error. I'm just confused why php would
> require the socket if it's not connecting to mysql locally. Does PHP
> require that the localhost have a mysql server installed even if I'm
> connecting to a remote server?
I don't suppose you could post the actual text of the error message,
too.
In the meantime you could try using the IP address instead of the host
name, in case DNS lookups are failing for some reason.
---
Steve