Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Tue Nov 07, 2006 1:30 pm
I have wrote a PHP script that connects to a MySQL server on another IP address but it trying to connect to localhost still. The script is as follows:
Code: Select all
mysql_connect("x", "x", "x");
mysql_select_db("x");
$query = mysql_query("SELECT * FROM x");
while ($results = mysql_fetch_array($query)) {
echo $results['id'], "<br>";
echo $results['fName'], "<br>";
echo $results['sName'], "<br>";
}
But I receive the following error:
PHP Warning: mysql_connect(): Access denied for user 'database'@'stesbox.co.uk' (using password: YES) in /var/www/html/php/test/db.php on line 3
Stesbox.co.uk is my own box that the PHP file is running on. Can someone advise my of what I've done wrong here please?
Regards,
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Tue Nov 07, 2006 1:33 pm
sorry for the dumb question, but did you enter in the new host instead of "localhost"
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Tue Nov 07, 2006 1:42 pm
Yeah. Sorry, removing the host wasn't a good idea for my post.
I can telnet to the IP on port 3306 fine so the MySQL connection is there but my script seems to want to connect to localhost
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Tue Nov 07, 2006 1:54 pm
Sorry, ignore my post below, not solved
Solved.
If I put the connection strings in ' ' rather than " " it connects fine.[/b]
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Nov 07, 2006 2:03 pm
You had a $ in your password?
(can't imagine another reason)
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Tue Nov 07, 2006 2:07 pm
Nope, the password is a plain ole string.
I tried using ' ' instead of " " just as a test. I've even tried setting the server address as the reverse DNS entry to the IP of the server but still without any connection success. Would someone mind trying my script on a server and let me know the results please?
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Tue Nov 07, 2006 2:13 pm
A-ha! It works.
My mistake is that when I was receiving
Access denied for user 'database'@'stesbox.co.uk' (using password: YES)
It looks to me like it was my server (stesbox.co.uk) that was rejecting the password.