Hi All - I am trying create classes for db connection and I am getting the following error
Thanks in advance
D
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'XXXXXXX_david'@'localhost' (using password: YES) in /home/djenning/public_html/dbconnection/connection.php on line 20
Cannot connect to the database
page: connection.php
<?php
class createConnection //create a class for make connection
{
var $host="localhost";
var $username="xxxxxxx_david"; // specify the sever details for mysql
var $password="XXXXXXXX";
var $database="databaseclass";
var $myconn;
function connectToDatabase() // create a function for connect database
{
$conn= mysql_connect($this->host,$this->username,$this->password);
if(!$conn)// testing the connection
{
die ("Cannot connect to the database");
}
else
{
$this->myconn = $conn;
echo "Connection established";
}
return $this->myconn;
}
function selectDatabase() // selecting the database.
{
mysql_select_db($this->database); //use php inbuild functions for select database
if(mysql_error()) // if error occured display the error message
{
echo "Cannot find the database ".$this->database;
}
echo "Database selected..";
}
function closeConnection() // close the connection
{
mysql_close($this->myconn);
echo "Connection closed";
}
}
?>
I am checking the connection here
Page: index.php
<?php
include ('connection.php');
$connection = new createConnection(); //i created a new object
$connection->connectToDatabase(); // connected to the database
echo "<br />"; // putting a html break
$connection->selectDatabase();// closed connection
echo "<br />";
$connection->closeConnection();
?>