Hi everyone,
I am expereincing some strange difficulties trying to get a MySQL class to function properly. I keep getting the following error message:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\myWebsite\theBusinessGame.com\class\mysql.class.php on line 23
Could not connect to the MySQL server.Access denied for user 'ODBC'@'localhost' (using password: NO)
Here is the code:
include "class/mysql.class.php";
$mysqldb = new mysql("127.0.0.1", "webTBG", "1111", "thebusinessgame");
$mysqldb->connect();
$mysqldb->select();
$mysqldb->query("SELECT businessID, worldID FROM business");
while($row = $mysqldb->fetchObject())
echo "$row->businessID ($row->worldID) <br/>";
Here is the MySQL class:
class mysql {
private $linkid; // MySQL link identifier
private $host; // MySQL server host
private $user; // MySQL user
private $pswd; // MySQL password
private $db; // MySQL database
private $result; // Query result
private $querycount; // Total queries executed
// Class constructor. Initializes the $host, $user, $pswd and $db fields.
function _construct($host, $user, $pswd, $db) {
$this->host = $host;
$this->user = $user;
$this->pswd = $pswd;
$this->db = $db;
}
// Connects to the MySQL database server.
function connect() {
try {
$this->linkid = mysql_connect($this->host, $this->user, $this->pswd);
if (!$this->linkid)
throw new Exception("Could not connect to the MySQL server.". mysql_error());
}
catch (Exception $e) {
die($e->getMessage());
}
}
// Selects the MySQL database.
function select() {
try {
if (! mysql_Select_db($this->db, $this->linkid))
throw new Exception("Could not connect to the MySQL database.");
}
catch (Exception $e) {
die($e->getMessage());
}
}
// Execute database query.
function query($query) {
try {
$this->result = mysql_query($query,$this->linkid);
if (! $this->result)
throw new Exception("The database query failed.");
}
catch (Exception $e) {
echo($e->getMessage());
}
$this->querycount++;
return $this->result;
}
// Determine total rows affected by query.
function affectedRows() {
$count = mysql_affected_rows($this->linkid);
return $count;
}
// Determine total rows returned by query.
function numRows() {
$count = mysql_num_rows($this->result);
return $count;
}
// Return query result row as an object.
function fetchObject() {
$row = mysql_fetch_object($this->result);
return $row;
}
// Return query result row as an indexed array.
function fetchRow() {
$row = mysql_fetch_row($this->result);
return $row;
}
// Return query result row as an associative array.
function fetchArray() {
$row = mysql_fetch_array($this->result);
return $row;
}
// Return total number of queries executed during the lifetime
// of this ob ject. Not required, but intersting nonethless.
function numQueries() {
return $this->querycount;
}
}
Should more information be required feel free to ask.
Thanks for any assistance that can be provided,
Abarak