public static function getProducts($count = self::SHOW_BY_DEFAULT)
{
$db = Db::getConnection();
$productsList = array();
$result = $db->query('SELECT id, name, price FROM product '
. 'WHERE status = "1"'
. 'ORDER BY id DESC '
. 'LIMIT ' . $count);
$i = 0;
while ($row = $result->fetch()) {
$productsList[$i]['id'] = $row['id'];
$productsList[$i]['name'] = $row['name'];
$productsList[$i]['price'] = $row['price'];
$i++;
}
return $productsList;
}
public static function getProducts($count = self::SHOW_BY_DEFAULT)
{
$db = Db::getConnection();
$productsList = array();
$st= $db->prepare('SELECT id, name, price FROM product '
. 'WHERE status = "1"'
. 'ORDER BY id DESC '
. 'LIMIT ' . $count);
if ($st && $st->execute()) {
$i = 0;
while ($row = $st->fetch()) {
$productsList[$i]['id'] = $row['id'];
$productsList[$i]['name'] = $row['name'];
$productsList[$i]['price'] = $row['price'];
$i++;
}
}
return $productsList;
}
if ($result = $db->query('SELECT id, name, price FROM product '
. 'WHERE status = "1"'
. 'ORDER BY id DESC '
. 'LIMIT ' . $count)) {
// твой код
} else {
else echo($db->error);
}
public static function getProducts($count = self::SHOW_BY_DEFAULT)
{
$db = Db::getConnection();
$result = $db->query('SELECT ....');
if (!$result) {
throw new \RuntimeException('SQL query error: ' . $db->error());
}
$productsList = [];
while ($row = $result->fetch()) {
// нет ни малейшего смысла перегонять из пустого в порожнее,
// т.е. из одного массива в другой
$productsList[] = $row;
}
return $productsList;
}