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);
if ($this->connection->connect_error) {
throw new \Exception('Error: ' . $this->connection->error . '<br />Error No: ' . $this->connection->errno);
}
$this->connection->set_charset("utf8");
$this->connection->query("SET SQL_MODE = ''");
}
public function query($sql) {
$query = $this->connection->query($sql);
if (!$this->connection->errno) {
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;
}
} else {
throw new \Exception('Error: ' . $this->connection->error . '<br />Error No: ' . $this->connection->errno . '<br />' . $sql);
}
}
<?
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('error_reporting', E_ALL);
class ControllerExtensionModuleDubli extends Controller {
public function index() {
$this->db->query('UPDATE `'.DB_PREFIX.'product` AS `p`
INNER JOIN (
SELECT `t`.`sku`, MIN(`p`.`product_id`) AS `product_id`
FROM (
SELECT `sku`, MIN(`price`) AS `price`
FROM `'.DB_PREFIX.'product`
WHERE `quantity` != 0
GROUP BY `sku`
) AS `t`
JOIN `'.DB_PREFIX.'product` AS `p`
ON `p`.`sku` = `t`.`sku` AND `p`.`price` = `t`.`price`
WHERE `p`.`quantity` != 0
GROUP BY `t`.`sku`
) AS `i` ON `i`.`product_id` = `p`.`product_id`
SET `p`.`status` = (`i`.`product_id` IS NOT NULL)')->rows;
echo "ok";
}
}
Почему он при ошибке не выбрасывает исключение с понятным описанием произошедшего.
Метод query вернул совсем не объект, вот вам и ошибка.
Запрос я рекомендую упростить
аааа, понял, вы так себе посты набивает, спамом бессмысленным ))))