Current time: 04-23-2014, 08:50 PM Hello There, Guest! (LoginRegister)

Post Reply 
PHP/MySQL Connection
01-19-2007, 05:56 PM
Post: #1
PHP/MySQL Connection
Hello,

I have been working on my site, and incorporating PHP and MySQL into it, including developing my own Blog Script.

I have been able to connect to the database fine, if I put the mysql_connect in the same file that is using the database, but I'm having one issue.

When I put the connection (same as when in the other file, I tripple checked this), code into an outside file, and include that via include_once, then call a function (I.E: dbConnect(); ) it errors out, saying it cannot connect to the mysql server.
Exact Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

As I said, I didn't change any of the actual connection code, I just put it in another file (db.inc.php), and included that file. Most sites I have read, say this is the way to do this.

Does anyone know what the issue is, or if Dreamhost might just have some sort of protection against this for some reason or another?

Thank you,
Craig (Abyss, -vI-)

-vI-
Visit this user's website Find all posts by this user
Quote this message in a reply
01-19-2007, 06:47 PM
Post: #2
PHP/MySQL Connection
this could be a silly answer Tongue

But I will just check the hostname, username, and password again. I will first echo the values before I connect to mysql database in *the other file*.

Save $97 (max discount) on dreamhost plans by using promo code: 97CRAZY.
Visit this user's website Find all posts by this user
Quote this message in a reply
01-19-2007, 08:03 PM
Post: #3
PHP/MySQL Connection
I always connect to MySQL through a server-side include, so that cannot be the problem; however, I don't use a function for this. Perhaps that is the problem?

--------
Simon's website
Save $100 on 1-year plans with promo code SCJESSEY100 (details)
Visit this user's website Find all posts by this user
Quote this message in a reply
01-21-2007, 07:07 PM
Post: #4
PHP/MySQL Connection
Oh believe me, I did. Twice or three times.

I even copied and pasted incase I was missing something. It works in one page, not in another.

In response to the second response, what do you do, just have the included file have the connection outside of a function, so it connects the moment it runs the include?

I'll try that, maybe that will work.

EDIT2:
It works now. The second response was right, it works that way. Thanks for the help! Smile
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: