Code: Select all
//1.5.6.x
if (isset($query->num_rows)) {
$data = array();
while ($row = $query->fetch_assoc()) {
$data[] = $row;
}
$result = new stdClass();
$result->num_rows = $query->num_rows;
$result->row = isset($data[0]) ? $data[0] : array();
$result->rows = $data;
unset($data);
$query->close();
return $result;
} else{
return true;
}
Code: Select all
//3.x
if ($query instanceof \mysqli_result) {
$data = array();
while ($row = $query->fetch_assoc()) {
$data[] = $row;
}
$result = new \stdClass();
$result->num_rows = $query->num_rows;
$result->row = isset($data[0]) ? $data[0] : array();
$result->rows = $data;
$query->close();
return $result;
} else {
return true;
}
Code: Select all
$my_query = $this->db->query($sql);
//nothing was found so then is $my_query = true ?
if ($my_query->num_rows) echo 'hi';
//Warning: Attempt to read property "num_rows" on bool
It will only return true if instanceof \mysqli_result is false, whatever this means?
Is there any benefit of updating 1.5.6.x to use($query instanceof \mysqli_result) and instead of the (isset($query->num_rows))? Or will it break?
I don't know what a namespace is and how it works with the backslash.
Code: Select all
//Since my 1.5.6.x uses:
final class DBMySQLi {
private $link;
public function __construct($hostname, $username, $password, $database) {
$this->link = new mysqli($hostname, $username, $password, $database);
//While 3.x uses:
namespace DB;
final class MySQLi {
private $connection;
public function __construct($hostname, $username, $password, $database, $port = '3306') {
$this->connection = new \mysqli($hostname, $username, $password, $database, $port);
($query instanceof dbmysqli_result)
or:
($query instanceof mysqli_result)
from this:
($query instanceof \mysqli_result)