Jump to content

Mysql connection getting denied for Apache, but i'm sending MY username?


Alex-Grim

Recommended Posts

As you can see from the code, i've declared all the variables in the class already, becasue they'll not change, but for some reason, when i try to connect and execute a query,  i get :

Access denied for user 'apache'@'localhost' (using password: NO)

 

But i've sent the password and the user name in my script?

<?php
echo "<h1>MySql.php is now included</h1>";
class MySql{
var $d="AlexGrim";
var $h="127.0.0.1";
var $u="webuser";
var $p="666";
var $connection;
var $query;
var $num;
var $array;
var $rows;


//	function MySql($h,$u,$p,$d){
//		$this->d = $d;
//		$this->h = $h;
//		$this->u = $u;
//		$this->p = $p;
//	}


function Connect(){
	$connection = mysql_connect("$h","$u","$p");
	mysql_select_db("$d", $connection);
}


function Close(){
	mysql_close($this->connection);
}


function Query($sql){
	$query = mysql_query($sql) or die(mysql_error());
	return $query;
}


function FetchRow($query){
	$rows = mysql_fetch_row($query);
	return $rows;
}

function FetchArray($query){
	$array = mysql_fetch_array($query);
	return $array;
}

function FetchNum($query){
	$num = mysql_num_rows($query);
	return $num;
}
}
?>

And here's the calling page, ignore the testing crap:

<?php
$br = "<br/><br/>";
$e = "<h1>ErRoR</h1>";
$myfile = "includes/classes/MySql.php";
if (file_exists($myfile)){
	echo "The file DOES exist. $br";
	include_once($myfile);
	echo "Page Loaded, and MySql.php included. $br";
}else{
   echo ($e."<h1>ErRoR! Content not available!</h1>");
}

$db = new MySql();
$con = $db->Connect();
$q = $db->Query("Select * from Comments");

?>

any variable in the class should be referenced with $this->[variable name] so the statement below

 

$connection = mysql_connect("$h","$u","$p");

 

should be

$connection = mysql_connect($this->h,$this->u,$this->p);

 

 

Thanx, that fixed it. I got another error afterwards about not being able to connect on 127.0.0.1(13), but i changed it from 127.0.0.1 to "localhost" and it's fine now, but i wonder what the difference really is.

Thanx again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.