本文整理汇总了PHP中query函数的典型用法代码示例。如果您正苦于以下问题:PHP query函数的具体用法?PHP query怎么用?PHP query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了query函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_by_id
function get_by_id($id, $conn)
{
$query = query("\n\t\tSELECT * FROM posts WHERE id = :id LIMIT 1", array("id" => $id), $conn);
if ($query) {
return $query->fetchAll();
}
}
示例2: get_products
function get_products($page, $per_page, $short = false)
{
$start = abs($page * $per_page);
$fields = $short ? 'product.id' : '*';
if (isset($_GET['sort'])) {
$sort_query = $_GET['sort'];
} elseif (!empty($_POST['sort'])) {
$sort_query = $_POST['sort'];
} else {
$sort_query = 'id_asc';
}
$cache_key = build_cache_key($page, $sort_query);
$result = get_cache($cache_key);
if (!$result) {
$sort_data = get_sort($sort_query);
$sort = $sort_data['sort'];
$sort_field = $sort_data['sort_field'];
if ($sort_field == 'id') {
$q = 'select ' . $fields . ' from product JOIN (SELECT ' . $sort_field . ' FROM product ' . $sort . ' LIMIT ' . $start . ',' . $per_page . ') as b ON b.id = product.id';
} elseif ($sort_field == 'price') {
$q = 'select ' . $fields . ' from product JOIN (SELECT id, price FROM product ' . $sort . ' LIMIT ' . $start . ',' . $per_page . ') as b ON b.id = product.id';
}
$res = query($q);
} else {
$q = 'select ' . $fields . ' from product where id in(' . $result . ');';
$res = query($q);
}
return $res;
}
示例3: netbios_setup
function netbios_setup($name)
{
$infp = XNODE_getpathbytarget("", "inf", "uid", $name, 0);
$stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $name, 0);
if ($infp == "" || $stsp == "") {
SHELL_info($_GLOBALS["START"], "infsvcs_setup: (" . $name . ") not exist.");
SHELL_info($_GLOBALS["STOP"], "infsvcs_setup: (" . $name . ") not exist.");
return;
}
$addrtype = query($stsp . "/inet/addrtype");
$ipaddr = query($stsp . "/inet/ipv4/ipaddr");
$devnam = query($stsp . "/devnam");
$hostname = query("device/hostname");
startcmd("hostname " . $hostname . "\n");
if ($ipaddr == "" || $devnam == "") {
return;
}
if ($addrtype == "ipv4" || $addrtype == "ipv6") {
//jef add + for support use shareport.local to access shareportmobile
$web_file_access = query("/webaccess/enable");
if ($web_file_access == 1) {
startcmd("netbios -i " . $devnam . " -r " . $hostname . " -r shareport.local -r shareport &\n");
startcmd("llmnresp -i " . $devnam . " -r " . $hostname . " -r shareport.local -r shareport &\n");
} else {
//jef add -
startcmd("netbios -i " . $devnam . " -r " . $hostname . " &\n");
startcmd("llmnresp -i " . $devnam . " -r " . $hostname . " &\n");
}
stopcmd("killall netbios");
stopcmd("killall llmnresp");
}
}
示例4: GetId
function GetId($username)
{
$query = "SELECT id FROM USERS WHERE username = '{$username}'";
$result = query($query);
$row = mysqli_fetch_array($result);
return $row[0];
}
示例5: exclui
public function exclui($obj)
{
foreach ($this->get_related_objects() as $obj) {
$obj->exclui();
}
return query('DELETE FROM ' . $this->get_table_name() . ' WHERE id = ' . $this->id);
}
示例6: check_dmz_setting
function check_dmz_setting($path, $addrtype, $lan_ip, $mask)
{
if (query($path . "/enable") == "1") {
anchor($path);
$hostid = query("hostid");
if ($hostid == "") {
set_result("FAILED", $path . "/hostid", i18n("DMZ IP Address cannot be empty."));
return "FAILED";
}
if ($hostid <= 0) {
set_result("FAILED", $path . "/hostid", i18n("DMZ IP Address is not a valid IP Address."));
return "FAILED";
}
if ($addrtype == "ipv4") {
$dmzip = ipv4ip($lan_ip, $mask, $hostid);
if (INET_validv4host($dmzip, $mask) == 0) {
set_result("FAILED", $path . "/hostid", i18n("DMZ IP Address is not a valid IP Address."));
return "FAILED";
}
}
} else {
set($path . "/enable", "0");
}
return "OK";
}
示例7: dhcps_setcfg
function dhcps_setcfg($prefix, $svc)
{
/* set dhcpX of inf */
$inf = cut($svc, 1, ".");
$svc = tolower(cut($svc, 0, "."));
$base = XNODE_getpathbytarget("", "inf", "uid", $inf, 0);
$dhcps_uid = query($prefix . "/inf/" . $svc);
set($base . "/" . $svc, $dhcps_uid);
/* copy the dhcp profile. */
$uid = INF_getinfinfo($inf, $svc);
$spath = XNODE_getpathbytarget($prefix . "/" . $svc, "entry", "uid", $dhcps_uid, 0);
$dhcps = XNODE_getpathbytarget("/" . $svc, "entry", "uid", $uid, 0);
if ($dhcps != "") {
if ($svc == "dhcps4") {
copy_dhcps4($spath, $dhcps);
} else {
if ($svc == "dhcps6") {
$_GLOBALS["SETCFG_DHCPS6_SRC_PATH"] = $spath;
$_GLOBALS["SETCFG_DHCPS6_DST_PATH"] = $dhcps;
$b = "/htdocs/phplib/setcfg/libs";
dophp("load", $b . "/dhcps6.php");
}
}
} else {
TRACE_error("SETCFG/DHCPS: no dhcps entry for [" . $uid . "] found!");
}
}
示例8: ShowEquipTable
function ShowEquipTable($query)
{
$numRows = mysqli_num_rows(query($query));
echo "<br><p class='center-align'>" . ($numRows > 0 ? $numRows : "Nenhum") . " " . ($numRows > 1 ? "items." : "item.") . "</p>";
PrintEquipTable(query($query));
echo "<div class=\"divider\"></div>";
}
示例9: check_qos_setting
function check_qos_setting($path)
{
$enable = query($path . "/device/qos/enable");
$auto = query($path . "/device/qos/autobandwidth");
if ($enable == "1") {
if ($auto == "0") {
if (isdigit(query($path . "/inf/bandwidth/upstream")) == "0" || query($path . "/inf/bandwidth/upstream") > 102400 || query($path . "/inf/bandwidth/upstream") < 1) {
set_result("FAILED", $path . "/inf/bandwidth/upstream", i18n("The input uplink speed is invalid."));
return "FAILED";
} else {
// Remove the leading zeros.
$upstream_dec = strtoul(query($path . "/inf/bandwidth/upstream"), 10);
set($path . "/inf/bandwidth/upstream", $upstream_dec);
}
} else {
set($path . "/device/qos/autobandwidth", "1");
}
$type = query($path . "/inf/bandwidth/type");
if ($type == "AUTO" || $type == "ADSL" || $type == "CABLE") {
} else {
set_result("FAILED", $path . "/inf/bandwidth/type", i18n("Unsupported Connection type be assigned."));
return "FAILED";
}
} else {
set($path . "/device/qos/enable", "0");
}
return "OK";
}
示例10: build
public function build($settings, $board_name)
{
global $config, $board;
openBoard($board_name);
$recent_images = array();
$recent_posts = array();
$stats = array();
$query = query(sprintf("SELECT *, `id` AS `thread_id`,\n\t\t\t\t(SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`,\n\t\t\t\t(SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `thread` = `thread_id` AND `num_files` IS NOT NULL) AS `image_count`,\n\t\t\t\t'%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error());
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $post['id']);
$post['board_name'] = $board['name'];
if ($post['embed'] && preg_match('/^https?:\\/\\/(\\w+\\.)?(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/)([a-zA-Z0-9\\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) {
$post['youtube'] = $matches[2];
}
if (isset($post['files'])) {
$files = json_decode($post['files']);
if ($files[0]->file == 'deleted') {
continue;
}
$post['file'] = $config['uri_thumb'] . $files[0]->thumb;
}
$recent_posts[] = $post;
}
$required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js', 'js/catalog.js');
foreach ($required_scripts as $i => $s) {
if (!in_array($s, $config['additional_javascript'])) {
$config['additional_javascript'][] = $s;
}
}
file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats, 'board' => $board_name, 'link' => $config['root'] . $board['dir'])));
}
示例11: vote
function vote($id)
{
$link = connect();
$query = "UPDATE quotes SET score = score +1 WHERE id={$id}";
query($query);
close($link);
}
示例12: putMailSettings
function putMailSettings($data)
{
// кнопка «Сохранить»
if ($data) {
foreach ($data as $data_key => $data_value) {
$sql = "UPDATE ntn_settings SET value = '{$data_value}' WHERE param = '{$data_key}'";
// file_put_contents('sql',$sql."\n",FILE_APPEND);
query($sql);
$sql = <<<EOD
INSERT INTO ntn_settings (param, value)
SELECT '{$data_key}', '{$data_value}'
FROM DUAL
WHERE NOT EXISTS (
SELECT 1
FROM ntn_settings
WHERE param = '{$data_key}' AND value = '{$data_value}'
)
EOD;
// file_put_contents('sql',$sql."\n",FILE_APPEND);
query($sql);
}
}
return true;
// почему-то эта функция всегда должна возвращать true, хотя ниже может быть и другой вариант развития событий
}
示例13: sConfig
function sConfig($key, $value)
{
$key = db_escape($key);
$value = db_escape($value);
$sql = "REPLACE INTO " . PREF . "config\n\t\tVALUE ('{$key}', '{$value}')";
query($sql);
}
示例14: getPersonalInfoById
function getPersonalInfoById($id)
{
$sql = "SELECT * FROM personal WHERE id='{$id}'";
$res = query($sql);
$result = mysql_fetch_object($res);
return $result;
}
示例15: query_route
/**
* get a specific route informations (name, color and stations along the route)
* from cache (MySQL database) based on route number.
*/
function query_route($route_number)
{
// get a specific route informations (name, color and stations along the route)
// from cache (MySQL database) based on route number. Store in array $query
$query = query("SELECT * FROM routes WHERE number = ?", $route_number);
// iterate each row, there is actually only 1 row in $query.
// 4 row in $query[0]: number, name, color and config
foreach ($query[0] as $key => $value) {
if ($key === 'config') {
// return an array of strings, each of which is a substring of string $value
// formed by splitting it by ',', each element in the array is a station along
// the route
$config = explode(',', $value);
foreach ($config as $station_abbr) {
// query current station
$query = query("SELECT * FROM stations WHERE abbr = ?", $station_abbr);
// build associative array
$station = [];
foreach ($query[0] as $key => $value) {
$station[$key] = $value;
}
$route['config'][] = $station;
}
} else {
// $route['numbr'] =.., $route['color'] =..,$route['name'] =..,
$route[$key] = $value;
}
}
// $route is an array with 3 basic elements and 1 element('config') that itself is a big array
return $route;
}