Hey guys, I'm sure this has been asked before, but I couldn't find any relevant answers with a search.
I am building a class to interface with MySQL(mostly for learning purposes). I have a function called getFirstRow(), which, as the name implies, is supposed to return an array of the first row. I am gettin gthis error when using it though..."Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')'"
Any help is mucho appreciated.
Here is the class
class dbConTran{
var $con;
var $numRows;
var $result;
var $resultArray;
var $firstRow = array();
var $lastRow = array();
// Open Database connection ---------
function dbOpen($name,$host,$user,$password){
$this->conn = @mysql_connect($host, $user, $password)or die ("Error Connecting to Database!");
@mysql_select_db($name, $this->con) or die ("Error Selecting Database!");
}//end dbOpen
// Close Database Connection --------
function dbClose(){
@mysql_close($this->con);
}//end dbClose
// INSERT, UPDATE or DELETE from Database --------
function dbIUD($sql){
$this->result = @mysql_query($sql);
if(!$this->result){
return false;
}else{
return true;
}//end if
}//end dbIUD
// SELECT FROM Database --------
function dbSelect($sql){
$this->result = @mysql_query($sql);
$this->numRows = @mysql_num_rows($this->result);
if(!$this->result){
return false;
}else{
return true;
}//end if
}//end dbSelect
// Get first row of dbSelect --------
function getFirstRow(){
$this->firstRow = mysql_fetch_array($this->result);
return $this->firstRow;
}//end getFirstRow
// Get last row of dbSelect --------
function getLastRow(){
while($this->resultArray = mysql_fetch_array($this->result)){
$this->$lastRow = &$this->resultArray;
}
}//end getLastRow
// Get number of rows from dbSelect --------
function getNumRows(){
return $this->numRows;
}//end getNumRows
}// End Of Database Class -------------------------------
And here is the implimentation of it
require("db_con_tran.class.php");
$db= new dbConTran();
$sql="SELECT * FROM tblBooks";
$database = "dbname";
$host= "localhost";
$user = "user";
$pass = "pass";
$db->dbOpen($database,$host,$user,$pass);
$db->dbSelect($sql);
echo $db->getNumRows();
$rowArray = array(db->getFirstRow());///error is here
print_r($rowArray);
$db->dbClose();