当前位置: 首页>>代码示例>>PHP>>正文


PHP SQL::getInst方法代码示例

本文整理汇总了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"]];
             }
         }
     }
 }
开发者ID:ksanderpugin,项目名称:fiteat,代码行数:17,代码来源:user.php

示例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'];
}
开发者ID:ksanderpugin,项目名称:fiteat,代码行数:31,代码来源:getuserrecipes.php

示例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);
    }
}
开发者ID:ksanderpugin,项目名称:fiteat,代码行数:37,代码来源:setuserrecipes.php

示例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 
    }
    ?>
开发者ID:ksanderpugin,项目名称:fiteat,代码行数:31,代码来源:checkProductInBase.php


注:本文中的SQL::getInst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。