I'm new to PHP and MYSQL development, and have been experiencing problems getting PHP to connect to MYSQL.
If I use either of the standard connection statements to connect to a database server running locally
$db = mysql_pconnect('localhost', 'php_webuser', 'php123xx');
or
$db = mysql_pconnect('127.0.0.1', 'php_webuser', 'php123xx');
the connection fails.
If however, I state the full network address of the local machine, e.g.
$db = mysql_pconnect('192.168.100.100', 'php_webuser', 'php123xx');
the connection is successful.
Can anyone point me in the direction of why the first method is failing?
Many thanks,
Bryan
PHP Can't Connect to MYSQL as LOCALHOST
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I think you got that right pickle. You can manage the users server by managing permissions. You can do it in phpMyAdmin or in the MySQL Administrator (or whatever commercial app you might use to manage your database). Just set the server that the user name is attached to to either 'localhost' or '%'.
Thanks guys - although I'm still a little unclear about this.
My database was setup with the offending user set as '%' for his location. This didnt work with 'localhost'.
I have now added 'localhost' as a specific location and all seems to be working ok.
Can't explain why the '%' option was refusing to let the 'localhost' connection from working though.
Bryan
My database was setup with the offending user set as '%' for his location. This didnt work with 'localhost'.
I have now added 'localhost' as a specific location and all seems to be working ok.
Can't explain why the '%' option was refusing to let the 'localhost' connection from working though.
Bryan
Or actually going into the `mysql` database & goofing around. I'm always a proponent of the 'learn to do it the hard way before the easy way' school.Everah wrote:You can do it in phpMyAdmin or in the MySQL Administrator (or whatever commercial app you might use to manage your database)
@~bdrew - I seem to remember that happening to me before & I too have no idea why it wouldn't work.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
What's your server version? That may explain it. I personally have had no experience with that problem so I couldn't tell you one way or the other why that would have happened.
pickle, with guys like you doing it the hard way and teaching guys like us that learn from guys like you, I'd never have to get into mysql from the CL.
pickle, with guys like you doing it the hard way and teaching guys like us that learn from guys like you, I'd never have to get into mysql from the CL.