MYSQL Problems


I’m attempting to implement the following Google Maps tutorial on my site:

I created a hostname-
I created a database- locations

I tried editing genxml.php as such:

// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());


// Opens a connection to a mySQL server
$connection=mysql_connect (, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());

That didn’t work, as it appeared the periods weren’t parsing properly, because it tried to connect to mapdomainnamecom .

I decided to edit the dbinfo.php file to pull the server from there…which appears to have worked, partially.

However, I now receive this error:

Warning: mysql_connect() [function.mysql-connect]: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /home/.fiver/username/domaindirectory/maptest/phpsqlsearch_genxml.php on line 15
Not connected : Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

I’m at a total loss.

What am I doing wrong here?

Thank you very much for any help!



You actually might be doing nothing wrong at all … are you sure that the new host name you created has been updated in DNS (can you browse directly to it in a browser)?

Sometimes it can take a while …



Additionally, this post might have some bearing on what you are experiencing:



Hi, I am getting the same error!

Warning: mysql_query() [function.mysql-query]: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /home/.squinky/********/confirmation.php on line 136

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/.squinky/***********/confirmation.php on line 136


Thanks rlparker, but it appears my sql stuff is located @ joecool:rosella.


I can, in fact, now browse to map.(mydomainname).com , as it brings up a myphpadmin interface. I believe I was doing so last night as well, just by clicking on ‘myphpadmin’ on the dreamhost web panel screen.

Still getting the same error this morning.


In the code you posted at the start of the thread, localhost and both appear to be without quotes. Try quoting them and see if that helps.

When PHP comes across unquoted strings that it can’t find anything else to do with, it will try to treat each string as if it is a quoted string. In the case of, PHP finds three strings joined together by concatenation (.) operators. That’s why it’s trying to connect to mapdomainnamecom rather than as you expect. If you put the whole thing in quotes, though, PHP won’t have to try to guess what you mean and you should end up with the result you want.


Hi Alpicola,

I took out of the dbinfo file and put it back into the original file it was in (when it had the parsing issues), and quoted it, works perfectly now!

Thank you all very much for your help!



I’m also getting the error. Thing is, I have an included file called ‘database.php’ which has all of my database functions. On some of my pages (all the ones inside an ‘admin’ folder) it works flawlessly. However, all other pages get this error.

To reiterate - the pages are calling the exact same function with the exact same parameters. On one page it will fail, while on another it gets this error:

Warning: mysql_connect() [function.mysql-connect]: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /home/**************/database.php on line 26

Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

MySQL server is lady: utter


Not completely sure what to make of your trouble since you say that it sometimes works and sometimes doesn’t. Let me ask a couple of questions to try to pin down what the problem might be.

First, the obvious question, have you confirmed that the parameters being given to the function are actually the same at runtime? If possible, try to echo the parameters that you call mysql_connect() wth immediately before you call mysql_connect() and make sure that the output is exactly the same on pages that work and pages that don’t.

Second, is there anything you can think of about scripts in admin/ that makes them special compared to the other scripts you’re trying to run?

Third, could you maybe post the relevant parts of database.php, including where you set up your parameters and the call to mysql_connect() itself? Of course, feel free to replace any secret information (like passwords) with dummy information :wink:

Glad to hear you got it working! :slight_smile:


Hopefully all relevant information:



class MySQLDB

/* Class constructor */
function MySQLDB(){

/* Make connection to database */
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

DB_SERVER, DB_USER etc are defined in the constants file.

At the end of database.php:

$database = new MySQLDB;

First few lines of admin/manageDocs.php (which works):

<?php include("../skins/_header.php"); ?> <?php function listDocs() { global $database; $result = mysql_query( "SELECT * FROM `****` WHERE `***_id` != '' "); $result2 = mysql_query( "SELECT * FROM `****` WHERE `***_id` != '' "); ********************* First few lines of viewImages.php (which doesn't work): ********************* <?php include("skins/_header.php"); ?> <?php function displayImages() { global $database; $result = mysql_query("SELECT * FROM `****` WHERE `***_id` != '' "); $result2 = mysql_query("SELECT * FROM `****` WHERE `***_id` != '' ");... ********************* Your idea about echoing the parameters was a good one, and might be leading me in the right direction (but no luck so far...) I echoed parameters right after the require("constants.php"); call in database.php. In the file that works, they output just like they shoulda! In the one that doesn't work, I get the exact same error, which seems to be saying to me that somehow that file is trying to call the database connection before it prints out the parameters... but for the life of me I can't figure out where or why. Thanks for any help.