本文整理汇总了PHP中SQL::getInst方法的典型用法代码示例。如果您正苦于以下问题:PHP SQL::getInst方法的具体用法?PHP SQL::getInst怎么用?PHP SQL::getInst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQL
的用法示例。
在下文中一共展示了SQL::getInst方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
private function __construct()
{
$this->auth = false;
$this->user_info = false;
if (array_key_exists('uk', $_COOKIE)) {
$uk = $this->decodeString($_COOKIE['uk']);
$uk_arr = explode("_", $uk);
$sql = SQL::getInst();
$data = $sql->query("SELECT * FROM users WHERE id = :id", [["name" => ":id", "val" => $uk_arr[0], "type" => SQL::PARAM_INT]]);
if ($data !== false && !empty($data)) {
if ($data[0]["ukey"] == $uk_arr[1]) {
$this->auth = true;
$this->user_info = ["id" => $data[0]["id"], "name" => $data[0]["name"], "soname" => $data[0]["soname"], "mail" => $data[0]["c_mail"] ? $data[0]["mail"] : false, "sex" => $data[0]["sex"], "birthday" => $data[0]["birthday"], "growth" => $data[0]["growth"], "weight" => $data[0]["weight"], "lifestyle" => $data[0]["lifestyle"], "norm_k" => $data[0]["norm_k"], "norm_b" => $data[0]["norm_b"], "norm_z" => $data[0]["norm_z"], "norm_u" => $data[0]["norm_u"], "norm_auto" => $data[0]["norm_auto"], "favorite_list" => $data[0]["favorite_list"], "black_list" => $data[0]["black_list"]];
}
}
}
}
示例2: ini_set
<?php
ini_set("display_errors", "Off");
include_once "../php/basic.php";
include_once "../php/config.php";
include_once "../php/sql.php";
include_once "../php/user.php";
header("Content-Type: application/json");
if (!User::getInst()->isAuthorized()) {
exit;
}
$sql = SQL::getInst();
$recipes = [];
$products = [];
$p_ids = [];
$composition = [];
$result = $sql->query("SELECT id, name FROM recipes WHERE uid = " . User::getInst()->getUserInfo()['id']);
foreach ($result as $row) {
$recipes[$row['id']] = $row['name'];
}
$r_ids = substr(json_encode(array_keys($recipes)), 1, -1);
$result = $sql->query("SELECT * FROM composition WHERE id_r IN ({$r_ids})");
foreach ($result as $row) {
$composition[$row['id_r']][$row['id_p']] = $row['weight'];
$p_ids[$row['id_p']] = true;
}
$p_ids_str = substr(json_encode(array_keys($p_ids)), 1, -1);
$result = $sql->query("SELECT id, name FROM products WHERE id IN ({$p_ids_str})");
foreach ($result as $row) {
$products[$row['id']] = $row['name'];
}
示例3: calcRecipesEnergy
function calcRecipesEnergy($recipe_ids)
{
$sql = SQL::getInst();
$comp = [];
$products = [];
$product_ids = [];
$recipes = [];
$result = $sql->query("SELECT * FROM composition WHERE id_r IN (:ids)", [["name" => ":ids", "val" => substr(json_encode(array_keys($recipe_ids)), 1, -1), "type" => SQL::PARAM_STR]]);
foreach ($result as $row) {
$comp[$row['id_r']][$row['id_p']] = $row['weight'];
$product_ids[$row['id_p']] = true;
}
$result = $sql->query("SELECT * FROM products WHERE id IN (:ids)", [["name" => ":ids", "val" => substr(json_encode(array_keys($product_ids)), 1, -1), "type" => SQL::PARAM_STR]]);
foreach ($result as $row) {
$products[$row['id']] = $row;
}
foreach ($recipe_ids as $key => $t_) {
$r_en = ['protein' => 0, 'fat' => 0, 'nzk' => 0, 'chol' => 0, 'carb' => 0, 'pv' => 0, 'na' => 0, 'k' => 0, 'ca' => 0, 'mg' => 0, 'p' => 0, 'fe' => 0, 'a' => 0, 'car' => 0, 're' => 0, 'te' => 0, 'b1' => 0, 'b2' => 0, 'ne' => 0, 'c' => 0, 'cal' => 0];
foreach ($comp[$key] as $id_p => $weight) {
foreach ($r_en as $name_cell => $num) {
$num += $products[$id_p][$name_cell] * $weight / 100;
$r_en[$name_cell] = $num;
}
}
$params = [];
$query = "UPDATE recipes SET ";
$val_id = 0;
foreach ($r_en as $name_cell => $val) {
$val_id++;
$params[] = ["name" => ":val" . $val_id, "val" => $val, "type" => SQL::PARAM_FLOAT];
$query .= $name_cell . "=:val" . $val_id . ", ";
}
$query = substr($query, 0, -2) . " WHERE id = :id";
$params[] = ["name" => ":id", "val" => $key, "type" => SQL::PARAM_INT];
$sql->execute($query, $params);
}
}
示例4: array_key_exists
<?php
include "../php/config.php";
include "../php/sql.php";
$word = array_key_exists("word", $_GET) ? $_GET['word'] : "";
$results = [];
if ($word) {
$results = SQL::getInst()->query("SELECT * FROM products WHERE name LIKE '%{$word}%'");
}
?>
<?php
if (!empty($results)) {
?>
<tbody>
<?php
foreach ($results as $row) {
?>
<tr>
<td><?php
echo $row['id'];
?>
</td>
<td><?php
echo $row['name'];
?>
</td>
</tr>
<?php
}
?>