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");
?>