MYSQL Problems


#1

I’m attempting to implement the following Google Maps tutorial on my site: http://code.google.com/support/bin/answer.py?answer=87134&topic=11364

I created a hostname- map.domainname.com
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());
}

became

// Opens a connection to a mySQL server
$connection=mysql_connect (map.domainname.com, $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!

-Justin


#2

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 …

–rlparker


#3

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

http://www.dreamhoststatus.com/2008/03/18/phil-isnt-feeling-very-well/

–rlparker


#4

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


#5

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


#6

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.


#7

In the code you posted at the start of the thread, localhost and map.domainname.com 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 map.domainname.com, PHP finds three strings joined together by concatenation (.) operators. That’s why it’s trying to connect to mapdomainnamecom rather than map.domainname.com 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.


#8

Hi Alpicola,

I took map.domainname.com 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!

-Justin


#9

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


#10

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:

@Justin:
Glad to hear you got it working! :slight_smile:


#11

Hopefully all relevant information:

Database.php:


require(“constants.php”);

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.