By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,910 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,910 IT Pros & Developers. It's quick & easy.

Cannot connect to MySQL server using PHP on localhost

P: n/a
I have set up MySQL on my home computer, and I am writing a PHP enabled web
site to run queries on this database.

I have created a database called 'weather' on mysql that I want to access
via my website.

I have also created a user with a password (this isn't the real one, but
I'll use this to illustrate my point)
User: carlotam
Password: blah
Host: localhost

To which user I have granted all on database weather.

Using a PHP call: I try:

$username="carlotam";
$password="blah";
$database="weather";
$host="localhost";

$var = $_POST['topic'];

echo "<center><h1>ESCape Database Query</h1></center>";
echo "You have queried <b>$var</b><br><br>";
echo "Your database is: <b>$database</b>.<br>";
echo "Your username is: <b>$username</b>.<br><br>";

mysql_connect($host, $username, $password);
@mysql_select_db($database) or die("Unable to select database
<b>$database</b> on <b>$host</b>.");
mysql_close();

And I keep getting the message "Unable to select database weather on
localhost."

Is there something wrong with the above, or is there something wrong with my
MySQL server configuration? My server is up and running, so I was wondering
if anybody can help with this problem?

If this information helps: I am running MySQL 5.0.15 server on a PowerMac G4
laptop. And yes, I did check to see if the server was running before I
checked the code.

-Carlo

Nov 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 11/17/05 7:26 AM, in article BF***********************@gmail.com, "Carlo
Tambuatco" <or*********@gmail.com> spoke thus:
I have set up MySQL on my home computer, and I am writing a PHP enabled web
site to run queries on this database.

I have created a database called 'weather' on mysql that I want to access
via my website.

I have also created a user with a password (this isn't the real one, but
I'll use this to illustrate my point)
User: carlotam
Password: blah
Host: localhost

To which user I have granted all on database weather.

Using a PHP call: I try:

$username="carlotam";
$password="blah";
$database="weather";
$host="localhost";

$var = $_POST['topic'];

echo "<center><h1>ESCape Database Query</h1></center>";
echo "You have queried <b>$var</b><br><br>";
echo "Your database is: <b>$database</b>.<br>";
echo "Your username is: <b>$username</b>.<br><br>";

mysql_connect($host, $username, $password);
@mysql_select_db($database) or die("Unable to select database
<b>$database</b> on <b>$host</b>.");
mysql_close();

And I keep getting the message "Unable to select database weather on
localhost."

Is there something wrong with the above, or is there something wrong with my
MySQL server configuration? My server is up and running, so I was wondering
if anybody can help with this problem?

If this information helps: I am running MySQL 5.0.15 server on a PowerMac G4
laptop. And yes, I did check to see if the server was running before I
checked the code.

-Carlo


Some new developments: I tried experimenting with mysql_connect() by running
it from the command line and got this error:

mysql_connect(): Client does not support authentication protocol requested
by server; consider upgrading MySQL client

Any help?

Nov 22 '05 #2

P: n/a
Carlo Tambuatco wrote:

Some new developments: I tried experimenting with mysql_connect() by
running it from the command line and got this error:

mysql_connect(): Client does not support authentication protocol requested
by server; consider upgrading MySQL client

Any help?


Google that:
"mysql_connect(): Client does not support authentication protocol requested
by server; consider upgrading MySQL client"

You will get plenty hits.

Like this one:

http://www.phplivesupport.com/docume...cle.php?aid=72

Good luck upgrading!

Regards,
Erwin Moller
Nov 22 '05 #3

P: n/a
yeah, if you're running PHP 4, it doesn't like MySQL 5 very much
PHP 5 uses mysqli which works

Nov 22 '05 #4

P: n/a
Meião wrote:
yeah, if you're running PHP 4, it doesn't like MySQL 5 very much
PHP 5 uses mysqli which works


Version numbers between PHP and MySQL doesn't have anything to do with
eachother.

However, if you recently upgraded your MySQL server software, you
probably need to upgrade your MySQL extension for PHP (Windows) or
recompile PHP to include the updated MySQL client (Linux/BSD).

--
Kim André Akerø
- ki******@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Nov 22 '05 #5

P: n/a
Kim André Akerø wrote:
Meião wrote:
yeah, if you're running PHP 4, it doesn't like MySQL 5 very much
PHP 5 uses mysqli which works


Version numbers between PHP and MySQL doesn't have anything to do with
eachother.

However, if you recently upgraded your MySQL server software, you
probably need to upgrade your MySQL extension for PHP (Windows) or
recompile PHP to include the updated MySQL client (Linux/BSD).


I found this issue myself yesterday when installing PHP on Windows with
MySQL 4.1. There's an incompatibility between the mysql client library
in the particular PHP binary I installed.

If you are not able to ensure the two have the same version (ie mysql
client version compiled into php is the same as that of mysql
installed) then you can simply change the password like so:

update user set password = OLD_PASSWORD('password here') where user =
'username';

flush privileges;

This of course assumes you have the rights to update user passwords...

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Nov 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.