Connecting to MySQL Database from PHP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
thysniu
Forum Newbie
Posts: 3
Joined: Tue May 31, 2005 7:06 am

Connecting to MySQL Database from PHP

Post by thysniu »

I know this is a cheesy question. I just started learning PHP and MySQL and I cant get it to connect.

Here's the code Im using:

Code: Select all

<?php
	 require_once('DB.php');
  	 // database connection setup section, user:pass@localhost/database

	 $dsn = "mysql://root:kujta21@localhost/timh";
	  
	 // establish the connection
	  
	 $db = DB::connect($dsn);
	 if (DB::isError($db)) {
		 die ($db->getMessage(  ));
	 }
		
	?>
This is how one of the PHP tutorials tells me to connect. What is wrong here?
I get this on the browser:

DB Error: connect failed

I am using PHP 4.3.11 and MySQL 4.1
I tried to figure all acceptable dsn combinations and none of them work
Some help anybody please?

thanks,
tim
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

use [ php ] tags...makes it much easier to read.

We can't see the actual connection to the database as it's in your \"included\" file.

it should look something like this:

Code: Select all

mysql_connect(\"host\",\"username\",\"password)
  or die(mysql_error());
it looks like you have it in a class somewhere.

post the code for that and we can better help you.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

might want to kick in a

Code: Select all

ini_set('error_reporting', E_ALL); 
ini_set('display_errors', TRUE);
My first guess is that MySQL is complaining about OLD PASSWORD.

With mysql_error() you can request more specific information about what went wrong...
thysniu
Forum Newbie
Posts: 3
Joined: Tue May 31, 2005 7:06 am

Still cant connect

Post by thysniu »

Thanks for the feedback guys. I used mysql_error() and now it shows me this:

"Client does not support authentication protocol requested by server; consider upgrading MySQL client"

This is great because I had the same problem while trying to run a php forum (phorum). I get the exact same message! I hope I can fix both.

The mysql version is 4.1 for windows installed in local machine(the latest I could get from mysql.com). Any ideas on what should I do to fix this?

When I used to run an older version of MySql with that PHP forum there was no such error. Everything worked fine in localhost. And I used to leave username and password blank to access a databases (which is a bit strange). I am guessing that the version might be the problem. Why I have no idea. Thats just an experience though, I hope you have a better clue.

Greatest thanks,

tim
thysniu
Forum Newbie
Posts: 3
Joined: Tue May 31, 2005 7:06 am

Post by thysniu »

Problem solved!
It was the old password..

thanks
tim
Post Reply