 |
|
 |
neutrall Level: Scholar

 Registered: 28-03-2004 Posts: 43
|
Problem with a SQL class...
Hi, I got the followin class for MySQL that I got from a book :
class MySQL {
var $host; //Server Host Name
var $dbUser; //MySQL User Name
var $dbPass; //MySQL User Password
var $dbName; //Database To Use
var $dbConn; //Resource Link Identifier
var $connectError; //Stores error messages
/**
* MySQL constructor
*/
function MySQL($host, $dbUser, $dbPass, $dbName)
{
$this->host = $host;
$this->dbUser = $dbUser;
$this->dbPass = $dbPass;
$this->dbName = $dbName;
$this->connectToDb();
}
/**
* Connection with MySql and Select a Database
*/
function connectToDb()
{
//Connect to MySQL Server
if (!$this->dbConn = @mysql_connect($this->host,$this->dbUser,$this->dbPass)) {
trigger_error('Could not connect to server');
$this->connectError = true;
//Select Database
} else if (!@mysql_select_db($this->dbName,$this->$dbConn)) {
trigger_error('Could not select database.');
$this->connectError = true;
}
}
/**
* Check for MySQL errors
*/
function isError()
{
if($this->connectError) {
return true;
}
$error = mysql_error($this->dbConn);
if (empty($error)) {
return false;
} else {
return true;
}
}
/**
* Return an instance of MySQLResult to fetch rows
*/
function &query($sql)
{
if (!$queryResource = mysql_query($sql, $this->dbConn)) {
trigger_error('Query failed: ' . mysql_error($this->dbConn) . ' SQL: ' . $sql);
}
return new MySQLResult($this, $queryResource);
}
}
|
And This Class which return the result from the query :
/**
* MySQLResult Data Fetching Class
*/
class MySQLResult {
var $mysql; //Instance of MySQL providing database connection
var $query; //Query Resource
/**
* MySQLResult constructor
*/
function MySQLResult(&$mysql, $query)
{
this->mysql = &$mysql;
this->query = $query;
}
/**
*Fetches a row from the result
*/
function fetch()
{
if($row = mysql_fetch_array($this->query, MYSQL_ASSOC)) {
return $row;
} else if ($this->size() > 0) {
mysql_data_seek($this->query,0);
return false;
} else {
return false;
}
}
/**
* Return the number of rows selected
*/
function size()
{
return mysql_num_rows($this->query);
}
/**
* Return the number Of Affected Row
*/
function affected()
{
return mysql_affected_rows($this->mysql->dbConn);
}
/**
* Return the Id ofthe last inserted row
*/
function insertID()
{
return mysql_insert_id($this->mysql->dbConn)
}
/**
* Check for MySQL errors
*/
function isError()
{
return %this->mysql->isError();
}
}
|
And I kept getting a error on the line (this->mysql =&$mysql;) :
function MySQLResult(&$mysql, $query)
{
this->mysql = &$mysql;
this->query = $query;
}
|
The Exact error message is : Parse error: syntax error, unexpected T_OBJECT_OPERATOR in J:\WEBSITE\WWW\class\mysql.php on line 119
can anyone help?
____________________________
A Stick give a wise man something to think about... and a fool, something to put in is mouth.
|
|
27-04-2005 at 07:27 PM |
|
|
|
|
 |
 |