473,473 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Cannot connect to MySQL server using PHP on localhost

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
5 2659
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jason mazzotta | last post by:
Hi, I'm rather new to both MySQL and PHP. I've been trying to use PHP to write to a MySQL database. I call mysql_pconnect to get a database connection, but then when I call mysql_db_select, I get...
1
by: Nikola Skoric | last post by:
Hi there, Is it possible to force PHP to connect to MySQL server using SSL? Or is there no way for PHP to connect to MySQL server on another machine by encrypted connection? -- "Now the...
2
by: pieter_hordijk | last post by:
Hi all, maybe this isn't a php question, but a MySQL question. If so I'm sorry for asking you guys to help me :) I know this question is asked often in NGs, but I couldn't find the answer...
0
by: Saravanan Kulandaivelu | last post by:
--------------B23FB769A9677B05B30099D1 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, I am getting the following error: mysqladmin: connect to server at...
1
by: shun | last post by:
Hello, I need an sample program to connect mysql server by using odbc. thanks in advance
15
by: rajbala | last post by:
hi all, I got the error like $ mysqladmin -h localhost -u root -p create bedrock Enter password: ****** mysqladmin: connect to server at 'localhost' failed error: 'Access denied for...
2
by: samnav | last post by:
Hello, I know this question was asked many times before but I couldn't find a solution that works for me. I've installed an apache server (2.2.6), PHP (5.2) and MySQL (5.0.45) in my windows XP...
2
by: mra | last post by:
pls help i have some probles while connecting mysql server from a client machine using visual basic. thanks in advance
1
by: mahesan | last post by:
How you connect to mySQL Server using PHP: we have a mySQL server in one host,say, 192.168.1.100 I am trying a program from 192.168.1.200, How do I make use of the databases in the mySQL...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.