Hi all,
I have been reading up on how OOPHP works and am trying to get into it but am finding very hard.
Today i have been trying to write my first ever class by myself, a mysql connect class. I thought this would be a good place to start. I am doing all my coding on my local machine running XAMPP.
ok so i thought i had it all down but no such luck, im getting the error
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\index.php on line 11
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\imaddresses\index.php on line 11
When ive seen this before its norm been the username or password for mysql have been set wrong, but ive checked this in my code by hard coding them into the method.
here is my code
classLib.php
<?php
class mysqlCon{
var $host;
var $username;
var $password;
var $dbName;
var $con;
var $selectDb;
function openDb(){
require("includes/connectDb.php");
$con = mysql_connect($host,$username,$password);
$selectDb = mysql_select_db($dbName, $con);
}
}
?>
connectDb.php
<?php
//Create new instance of the class mysqlCon
$con = new mysqlCon();
//set vars
$con->host = "localhost";
$con->username = "root";
$con->password = "password";
$con->dbName = "imaddresses";
//use the connect method here
$con->openDb();
?>
index.php
<?php include("library/classLib.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
</head>
<body>
<?php
$sql = mysql_query("SELECT* FROM users");
?>
</body>
</html>
Maybe im doing sum thing real dumb, but an help would be great. Like i said this is my first ever class soooo go easy on my lol :queasy:
cheers