Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Parse error: syntax error, unexpected '->'

Posted on 2013-11-11
5
Medium Priority
?
431 Views
Last Modified: 2013-11-11
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?????
0
Comment
Question by:tonelm54
  • 3
5 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39638132
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
0
 

Author Comment

by:tonelm54
ID: 39638362
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'"
0
 

Author Comment

by:tonelm54
ID: 39638388
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
0
 
LVL 44

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 39638480
Pass the variable into your class constructor:

class claTicketTable {

  var $sqlConn;

  function __construct($mysqli) {
        $this->sqlConn = $mysqli;
  }
}

$mysqli = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);
$myClass = new clasTicketTable($mysqli);

Open in new window

Then throughout your class you can access it using the local sqlConn variable:

$this->sqlConn->query("SELECT ...");
0
 

Author Closing Comment

by:tonelm54
ID: 39638494
Thank you :-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question