Connecting Tech Pros Worldwide Forums | Help | Site Map

mysql connection problem.

Newbie
 
Join Date: Dec 2007
Posts: 27
#1: Nov 3 '08
when i am trying to connect to mysql from my php page i got the below message
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2) in /home/content/d/e/a/dealersmax/html/db.php on line 6

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/content/d/e/a/dealersmax/html/db.php on line 7

I am using the below php code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $conn1 = mysql_connect("localhost","username","password");
  3.           $db1=mysql_select_db("database",$conn1);
  4.           ?>
can anyone please tell me how can i solve this?

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,947
#2: Nov 3 '08

re: mysql connection problem.


Add some or die() handlers to your queries.

Expand|Select|Wrap|Line Numbers
  1. mysql_query($query) or die(mysql_error());
  2.  
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,440
#3: Nov 3 '08

re: mysql connection problem.


There might be couple of reasons for this: the server is down, the database password was changed, the server has changed name, the communication between web server and database server is disturbed by a firewall. anyway your coding is good to use, but make sure to trap your errors always.
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#4: Nov 3 '08

re: mysql connection problem.


Hi.

The error you posted is typically shown when you try to connect to a Linux based MySQL server that is not yet running.

Make sure the MySQL server is in fact running on your server.
Reply