<?php /* pseudo mysqli object */ class Foo { public $error; public function __construct($host, $user, $passwd, $dbname) { $this->host = $host; $this->user = $user; $this->pass = $passwd; $this->$dbname = $dbname; } public function query($sql, $resultmode) { if ($sql !== 'Valid Query') { $this->error = 'Expected "Valid Query"'; } return new Bar; } } /** pseudo mysql_stmt object */ class Bar { public function fetch_assoc() { echo 'I was successful'; } } class Conn { private $conn; public function __construct(...$args) { $this->conn = new Foo(...$args); } public function query($query, $resultmode = 1) { $d = $this->conn->query($query, $resultmode); if (!empty($this->conn->error)) { throw new \RuntimeException($this->conn->error); } return $d; } } //Your example $con = 'my_var'; $$con = new Conn('host', 'user', 'pass', 'base'); //example usage of valid query $q = $my_var->query('Valid Query'); $q->fetch_assoc(); echo PHP_EOL. '-----' . PHP_EOL; //example use of invalid query throwing an exception before `fetch_assoc` $q = $my_var->query('This is not valid'); $q->fetch_assoc();
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`