a weird error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

a weird error

Post by Obadiah »

ok....i finnally got that to work but now...after i worked out the bugs for my include pages i get

Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'admin'@'localhost' (using password: NO) in on line 5


line 5 of the file its pointing to says

Code: Select all

$cxn = mysqli_connect($host,$user,$password)
		or die ("Couldn't connect to server.");
the whole file being

Code: Select all

<?php
function Connect_to_db($filename)
{
	include($filename);
	$cxn = mysqli_connect($host,$user,$password)
		or die ("Couldn't connect to server.");
	$db = mysqli_select_db($cxn,$database)
		or die ("Coulden't select database.");
}
?>
and here is the kicker.....when i change the password in the and user name to access the database in the main file(the main file being simply)

Code: Select all

<?php
	$host = "localhost";
	$user = "****";
	$passwd = "****";
	$database = "********";
?>
it still says the same thing....am i going about this the wrong way?

Everah | Edited to remove potentially private data.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

mysql error -> http://www.mysql.com/search/index.php
search for access denied


edit: also try

Code: Select all

<?php
function Connect_to_db($filename)
{
	require $filename;
	
	if ( !isset($host,$user,$password,$database) ) {
		die('one or more required connection parameters not set');
	}
	
	echo "Debug: mysqli_connect($host,$user,$password)";
	$cxn = mysqli_connect($host,$user,$password)
		or die ("Couldn't connect to server.");
	$db = mysqli_select_db($cxn,$database)
		or die ("Coulden't select database.");
} 
?>
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Post by Obadiah »

but im using xampp....that link tells me to connect to my database using CMD but when i try that i get a error that says bad syntax...so next i tried just going to the folder in xampp that mySQL is installed in and it had a .exe when i clicked it it didnt promt me for anything it was just a blank cmd screen without a path and just a prompt....what do i do
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

forget it.
What about the code snippet?
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Post by Obadiah »

it says

one or more required connection parameters not set. can u explain to me the difference in your snippet....why it gave a different error and why mine gave a connection error? how can i avoid the connection issue in the future?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

My version tests, wether there are those variables you want to use with mysqli_connect or not. At least one is not.
tip:
Access denied for user 'admin'@'localhost' (using password: NO)
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Post by Obadiah »

so what do i do? i dont mean to be a neusence but im new to the whole php deal and you said that its testing to see whether or not the password is correct...if i changed the password the error is the same...thats what i dont understand...if im thinking correctly its wanting to connect to mySQLadmin right...so if i put in the correct username and password it should work right? but its not....why?

and what did you mean by
volka wrote:My version tests, wether there are those variables you want to use with mysqli_connect or not. At least one is not.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Code: Select all

<?php
        $host = "localhost";
        $user = "admin";
        [[[[[[[[[[[$passwd]]]]]]]]]]]] = "admin";
        $database = "CustomerDirectory";
?>

Code: Select all

<?php
function Connect_to_db($filename)
{
        include($filename);
        $cxn = mysqli_connect($host,$user,[[[[[[[[[[[[$password]]]]]]]]]]]]]])
                or die ("Couldn't connect to server.");
        $db = mysqli_select_db($cxn,$database)
                or die ("Coulden't select database.");
}
?>
OK?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Run a PHP info page...

Code: Select all

<?php
phpinfo();
?>
And look at the part where it says MySQL Client API Version. What does it say? What version of MySQL are you running?

Code: Select all

SELECT VERSION();
Please post back with that information.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

@Everah: The error message for that is "Client does not support authentication protocol" ;)
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Post by Obadiah »

@Everah=the mysql version im using is 5.0.21

@ole= i understand what u are trying to say but if you would have read the message i wrote earlier to its completion you would have read that i tried to change the password to see if that would fix the problem and it didnt, and then i asked volka to explain the difference in the code that he wrote and the tutorial that i was following so that i could explain how it worked(thanx volka btw). Ive never worked with either of these languages (php and mySQL) before now so there is alot i dont understand and im following a tutorial that dosent cover debugging or error handling (and not to mention has alot of typos) to get a larger product for my company complete so the comment with the brackets around the password was hardly necessary.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Obadiah: OK, Well I haven't been following this thread very closely I just saw that.
User avatar
bmcewan
Forum Commoner
Posts: 55
Joined: Wed Jun 02, 2004 7:19 am
Location: West Yorkshire, UK.

Post by bmcewan »

it is not the password per se that is the problem, but the password variable name, which is what ole was trying to point out.

Code: Select all

$passwd = "****";

Code: Select all

$cxn = mysqli_connect($host,$user,$password)
notice any difference?

EDIT: Took too long to finish my reply.
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Post by Obadiah »

ok....i think i get it....but what password is it looking for is it looking for the mySQLadmin, the phpMYAdmin() bc thats where i created the database in....or am i still miles away from the answer...anyone? also if im thinking correctly the line

Code: Select all

if ( !isset($host,$user,$password,$database) )
is testing to see whether or not those variables are set. and in the file it points to somefile.php they are so thats why im not understanding. can someone explain to me what im doing wrong?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Obadiah wrote:ok....i think i get it...
I'm not sure you did.
You noticed the difference
$passwd <- $passwd = "****";
$password <- mysqli_connect($host,$user,$password)
and have corrected that error?
Post Reply