0

I'm currently setting up a development environment on Ubuntu for an existing working php / mysql website.

When attempting to generate a page, I get the following error:

PHP Fatal error:  Uncaught Error: Call to a member function execute() on boolean in /var/www/html/dev.example.com/class/wtd.data.class.php:55\nStack trace:\n
#0 /var/www/html/dev.example.com/class/rollcage.class.php(295): wtdMySQL->select('vehicles LEFT J...', 'vehicle', 'CASE WHEN vehic...', '1 AND vehicles....', 'results', 'vehicles.vehicl...', 'vehicleModel,ve...')\n
#1 /var/www/html/dev.example.com/layouts/roll-cage-selector.php(3): rollcage->getRollCageModels('Motorsport', '', 'Live')\n
#2 /var/www/html/dev.example.com/index.php(562): include('/var/www/html/d...')\n#3 {main}\n  thrown in /var/www/html/dev.example.com/class/wtd.data.class.php on line 55

The code that generates this error looks like this:

function select($table, $prefix=NULL, $columns="*", $where=NULL, $return="results", $orderby=NULL, $group=NULL, $limit=NULL){
    global $errors;

    $this->set_charset("utf8");

    $sql = "SELECT {$columns} FROM {$table}";
    if($where) $sql .= " WHERE {$where}";
    if($group) $sql .= " GROUP BY {$group}";
    if($orderby) $sql .= " ORDER BY {$orderby}";
    if($limit) $sql .= " LIMIT {$limit}";
    if($errors==3){
        print "<div class='error'>$sql</div>";
    }

    $prepare = $this->prepare($sql);
    $prepare->execute();
    $prepare->store_result();

The SQL is generated correctly and returns a single row. A var_dump of $prepare shows this:

object(mysqli_stmt)#3 (10) { ["affected_rows"]=> int(0) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(0) ["field_count"]=> int(28) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) }

As this works on the live server, I'm guessing this could be environmental, but am I missing anything obvious?

Any pointers appreciated.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Christian Mayne
  • 1,709
  • 7
  • 26
  • 42
  • Did you amend your Database connection to match the LIVE servers requirements?? – RiggsFolly Jul 13 '16 at 12:01
  • Or did you load all the required tables to your live database. This error normally means a `->prepare` has failed – RiggsFolly Jul 13 '16 at 12:01
  • 1
    You have an SQL error, so check for the error on execute failure. – Jeff Puckett Jul 13 '16 at 12:02
  • The generated SQL works correctly if I run directly against the database. – Christian Mayne Jul 13 '16 at 12:04
  • Error tells that you trying to call execute method on boolean. `mysqli->prepare` returns boolean when errors happen. The only possible reason why `var_dump` tells you that `$prepare` is `mysqli_stmt`, is that you checking different query. – Arnial Jul 13 '16 at 12:09
  • `echo $sql` and post query!! – Saty Jul 13 '16 at 12:11
  • try print `mysqli->error` after each `prepare` – Arnial Jul 13 '16 at 12:11
  • Here's the generated $sql: `SELECT * FROM pages WHERE 1 AND (LOWER(pageUUID) = 'wtd' OR LOWER(pageUrl) = 'wtd') AND pageParent = '' AND pageStatus = 'Live'` – Christian Mayne Jul 13 '16 at 12:14
  • Turning errors on I can now also see this: `Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dev_example.vehicles.vehicleUUID' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by in /var/www/html/dev.example.com/class/wtd.data.class.php on line 51` – Christian Mayne Jul 13 '16 at 12:16
  • Please not that this function is highly inconvenient in use and extremely vulnerable to all sorts of injections. Because the use of preare/execute here is essentially pointless. – Your Common Sense Jul 13 '16 at 12:16
  • 1
    Ok so you are using a different version of MYSQL on the LIVE, probably a more recent version. Guess you should upgrade your test environment, match the configs and retest everything – RiggsFolly Jul 13 '16 at 12:18

0 Answers0