Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/MySQL Error

Status
Not open for further replies.

dagoat10

Programmer
Jun 3, 2010
74
US
I am trying to connect to a database on a server that i have permission on, but not as root. I do however have permission to the database i created , but it's not in the standard directory of /var/lib/mysql/
I had to install a local user copy of it and create my own config file. also i created my own local directory for mysql because i can't use the root version, due to not being root. I'm using PHP to try to connect and this is what the page is returning

Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) in mydirectory/test.php on line 6

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) in mydirectory/ on line 6
Unable to select database

Here is the PHP script:

<?php
$user="myuser";
$password=
$database="demo";
mysql_connect(localhost, $user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM customers";
$result=mysql_query($query);
mysql_close();
?>

I do have a password value but i removed it.

So what could i be doing wrong?
 
mysql listens on a default port. it is possible that you can persuade mysql to bind to a high port number without root authorisation. it depends on the OS.

and you are attempting to attach to your mysql server instance via the default socket. which is odd, since you intend to bind to the default port on localhost. this would not have worked because you don't have root perms, but anyway, the host name should be expressed as a string not a constant.

anyway, the right data to use will be that specified in your .my.cnf file. i would either choose a high port and see whether that works (include the port number in your hostname) or specify a socket in your home directory.

for further assistance please take a walk over to the mysql forum.
 
For mysql, "localhost" means that a socket or named pipe is used. If you want to connect over TCP to the local machine, use 127.0.0.1.

Apart from that, check if you can connect with the command-line client. Is MySQL running on the local machine? It seems that the server program is not accessible (you would have got a different message for an authentication failure).

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
ok, well now it says unable to connect to database. And i made the hostname a variable. what's wrong now?
 
Can you connect to the database using the command-line client or with another program?

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top