Sb::query
Usage
PDOStatement Db::query(string $sql, [ ... $args ])Description
Execute SQL statement against the database.Parameters
Parameter | Required | Type | Description |
---|---|---|---|
$sql | Yes | string | The SQL statement to execute, which can contain placeholders (ie. %s, %i, %b, et al). For full details, please see the Database Placeholders page of the documentation. |
$args | No | desc= |
Return Value
Returns instance of a PDOStatement of the query executed. If this is a select query, it also acts as an iterator allowing you to go through the rows within the result set.Examples
Query
// Select active products of category id# 31, more expsnve that $34.95
$cat_id = 31;
$price = 34.95;
$rows = $this->db->query("SELECT * FROM products WHERE is_active = %b AND category_id = %i AND price >= %d ORDER BY created_at DESC LIMIT 25 OFFSET 50", true, $cat_id, $price);
foreach ($rows as $row) {
print_r($row);
}
// Deactivate all products less than $20
$price = 20;
$this->db->query("UPDATE products SET is_active = %b WHERE price < %d", false, $price);