Link to home
Start Free TrialLog in
Avatar of tonelm54
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:-
        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() . "));");

Open in new window


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() {
  }
}

Open in new window


Can anyone see what Im doing wrong?????
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

I don't know if you can use 'global' there but you are definitely not assigning the results of $mysqli->query to a variable.  Without assigning it to a variable you can't use the results.

http://us2.php.net/mysqli_query
Avatar of tonelm54
tonelm54

ASKER

Sorry, dont know how I missed that from my example code, it is there....

If I use:-
$resTable = $mysqli->query("select uuid();");

Open in new window


I get "Notice: Undefined variable: mysqli"

If I use:-
$resTable = global $mysqli->query("select uuid();");

Open in new window


I get "Parse error: syntax error, unexpected 'global'"
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
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you :-)