tonelm54
asked on
Parse error: syntax error, unexpected '->'
Im converting some of my code from old style procedure to OOP in order to tidy up the code a bit better, however Im a little confused on my error saying "Parse error: syntax error, unexpected '->'"
The error Im getting is on the line:-
So the variable $mysqli is declared outside the class, in another class, but it seems to be raising the parse error in the building of the SQL statment.
My code which replicates the issue:-
Can anyone see what Im doing wrong?????
The error Im getting is on the line:-
global $mysqli->query("select `ticket`.*, `job`.*, `joblocation`.* from `ticket` left join `job` on `job`.`serialNumber` = `ticket`.`jobSerialNumber` left join `joblocation` on `job`.`locationID` = `joblocation`.`locationID` where ((" . $this->buildWhereCompany() . ") and (" . $this->buildWhereSite() . ") and (" . $this->buildWherejobManufacturer() . "));");
So the variable $mysqli is declared outside the class, in another class, but it seems to be raising the parse error in the building of the SQL statment.
My code which replicates the issue:-
$mysqli = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);
class claTicketTable {
function __construct() {
global $mysqli->query("select `ticket`.*, `job`.*, `joblocation`.* from `ticket` left join `job` on `job`.`serialNumber` = `ticket`.`jobSerialNumber` left join `joblocation` on `job`.`locationID` = `joblocation`.`locationID` where ((" . $this->buildWhereCompany() . ") and (" . $this->buildWhereSite() . ") and (" . $this->buildWherejobManufacturer() . "));");
}
private function buildWhereCompany() {
$sqlWhere = "(`joblocation`.`company` like \"%\")";
return $sqlWhere;
}
private function buildWhereSite() {
$sqlWhere = "(`joblocation`.`site` like \"%\")";
return $sqlWhere;
}
private function buildWherejobManufacturer() {
$sqlWhere = "(`joblocation`.`manufacturer` like \"%\")";
return $sqlWhere;
}
function drawTable() {
}
}
Can anyone see what Im doing wrong?????
ASKER
Sorry, dont know how I missed that from my example code, it is there....
If I use:-
I get "Notice: Undefined variable: mysqli"
If I use:-
I get "Parse error: syntax error, unexpected 'global'"
If I use:-
$resTable = $mysqli->query("select uuid();");
I get "Notice: Undefined variable: mysqli"
If I use:-
$resTable = global $mysqli->query("select uuid();");
I get "Parse error: syntax error, unexpected 'global'"
ASKER
I think my issue is with getting access to the variable $mysqli which is created outside my class, but dont know how (or even it if it is possible) to either get access the the variable $mysqli created externally, or how to pass the reference of the variable through as there is no point in creating a new instance.
Thank you
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you :-)
http://us2.php.net/mysqli_query