本文整理汇总了PHP中Db::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::init方法的具体用法?PHP Db::init怎么用?PHP Db::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: control
/**
* 发送控制指令
*
* @param params params
*/
protected static function control($params, $cmd)
{
if (!isset($params["mid"])) {
return Error::getRetString(10007);
}
$mid = $params["mid"];
$uuid = $_GET["uuid"];
$udid = $_GET["udid"];
$db = Db::init();
//验证用户
$user = $db->get_var("select user from user where uuid=\"{$uuid}\"");
if (!isset($user)) {
return Error::getRetString(10009);
}
//uuid无效
if ($db->query(<<<EOD
select mid from device_modules where mid="{$mid}" and udid="{$udid}"
and exists(select udid from user_device where user="{$user}" and udid="{$udid}")
EOD
)) {
//本地验证成功,开始与设备进行通信
$string = file_get_contents("php://input");
return self::sendToDevice($string, $uuid, $udid, $uuid);
return Error::getRetString(0);
} else {
return Error::getRetString(10016);
}
return Error::getRetString(0, array("uuid" => $uuid, "udid" => $udid, "cmd" => $cmd));
}
示例2: init
static function init()
{
// override autoloader
spl_autoload_register('SnS::autoload');
self::$files_base = dirname(dirname(__FILE__)) . "/files/";
Db::init();
}
示例3: run
public static function run($string, $udid, $email)
{
$ret = DeviceControl::sendTo($string, $email, $udid, $email);
$array = Protocol::decode($ret);
if (isset($array["result"])) {
$ret_string = $array["result"];
$data = $array["result"];
$json = json_decode($string, true);
$mid = $json["params"]["mid"];
$db = Db::init();
switch ($json["method"]) {
case "TurnOn":
_Notify::add($mid, $_GET["u"], "开启");
$stat = 1;
break;
case "TurnOff":
_Notify::add($mid, $_GET["u"], "关闭");
$stat = 0;
break;
default:
$stat = 0;
}
$db->query("update device set stat={$stat} where mid='{$mid}'");
} else {
if (isset($array["data"])) {
$ret_string = $data;
} else {
$ret_string = $ret;
//echo Error::getRetString(-1);
}
}
return $ret_string;
}
示例4: init
static function init()
{
$version_file = APP_PATH . '/../version';
if (file_exists($version_file)) {
self::$version = trim(@file_get_contents($version_file));
}
$config_file = APP_PATH . '/config/config.php';
if (!file_exists($config_file)) {
throw new Exception("No config file");
}
$config = (include $config_file);
self::$config = $config;
self::$env = $config['env'];
#self::$context = new stdClass();
self::$context = new Context();
Logger::init($config['logger']);
if (isset($config['db'])) {
Db::init($config['db']);
}
if (get_magic_quotes_gpc()) {
foreach ($_GET as $k => $v) {
$_GET[$k] = Text::stripslashes($v);
}
foreach ($_POST as $k => $v) {
$_POST[$k] = Text::stripslashes($v);
}
foreach ($_COOKIE as $k => $v) {
$_COOKIE[$k] = Text::stripslashes($v);
}
}
$_REQUEST = $_GET + $_POST + $_COOKIE;
}
示例5: add
public static function add($mid, $did, $email, $msg)
{
$db = Db::init();
date_default_timezone_set("Asia/Chongqing");
$name = $db->get_var("select name from device where did='{$did}'");
$msg = $name . " " . $msg;
// $time = (string)date("H:i:s");
$time = (string) date("m-d h:ia");
return $db->query("insert into user_notify(mid, did, email, msg, time) select '{$mid}', '{$did}', '{$email}', '{$msg}', '{$time}' from dual");
}
示例6: verify_user
function verify_user($user)
{
$db = Db::init();
$result = $db->get_results("select user from authorization where stat=1 and user='{$user}'");
//var_dump($result);
if (isset($result[0])) {
return true;
}
return false;
}
示例7: _List
public static function _List($params)
{
$db = Db::init();
$tdidlist = $db->get_col("select user from authorization where stat=1");
$results = array();
foreach ($tdidlist as $tdid) {
$results[] = array("user" => $tdid);
}
return json_encode(array("code" => 0, "msg" => "ok", "results" => $results));
}
示例8: _turn
function _turn($params, $code, $all = false)
{
$db = Db::init();
if ($all == true || isset($params["mid"]) && isset($params["no"])) {
$mid = strtoupper($params["mid"]);
$no = $params["no"];
$type = substr($mid, 0, 1) . "\n";
if (verify_mid($mid) == false) {
//id不存在
return json_encode(array('code' => 30004, 'msg' => "mid no exist"));
}
$data = $db->get_var('SELECT number FROM "switch_info" where switchid="' . $mid . '"');
if (isset($data)) {
$data = sprintf("%02X", $data);
switch ($type) {
case '1':
//电池版开关
$json = array("id" => "{$mid}", "code" => $code, "param" => 1 << $no - 1, "data" => "{$data}", "timeout" => 2000, "response" => 0);
break;
case '4':
//零火版开关
//零火版开关
default:
$json = array("id" => "{$mid}", "code" => $code, "param" => 1 << $no - 1, "data" => "{$data}", "timeout" => 500, "response" => 0);
break;
}
for ($i = 0; $i < 100; $i++) {
$res = Uart::send(json_encode($json));
if (isset($res["stat"])) {
switch ($res["stat"]) {
case 0:
return json_encode(array('code' => 0, 'msg' => "ok"));
break;
case 40004:
//射频模块正忙
usleep(200000);
continue;
return json_encode(array('code' => 30006, 'msg' => "system is busy"));
default:
return json_encode(array('code' => 32004, 'msg' => "communication fault(" . $res["stat"] . ")"));
}
}
}
return json_encode(array('code' => 32004, 'msg' => "communication fault(" . $res["stat"] . ")"));
} else {
//读数据库错误
return json_encode(array('code' => 30005, 'msg' => "read data from database error"));
}
} else {
return json_encode(array('code' => 30003, 'msg' => "params error"));
//参数不完整
}
}
示例9: _Login
/**
*
* @param params params
*/
public static function _Login($params)
{
if (is_array($params) && isset($params["account"])) {
$account = $params["account"];
$db = Db::init();
$uuid = self::createUUID();
if ($db->query("select email from user where email=\"{$account}\"")) {
$db->query("update user set uuid=\"{$uuid}\" where email=\"{$account}\"");
return Error::getRetString(0, array("uuid" => $uuid));
}
} else {
return Error::getRetString(10007);
}
}
示例10: __construct
/**
*
* Simpler Konstruktor
* benötigt alle Daten zum Online Banking Account
*
* @param String $bank_code (Bankleitzahl)
* @param String $banking_login (Benutzerkennung)
* @param String $banking_pin (Pin)
* @param String $account_number (Kontonummer)
* @param string $bank_user_name (Name des Kontoinhabers)
* @param string $tanmedium_id (Tan-Medium ID z.B. Bezeichnung der Mobilnummer bei Sparkasse)
* @param string $locale (Länderkennung)
*
*/
public function __construct($bank_code, $banking_login, $banking_pin, $account_number, $bank_user_name = false, $tanmedium_id = false, $locale = 'DE')
{
$this->shell = new Exec();
$this->is = '';
$this->config_dir = DIR_AQCONFIG . $bank_code . '/' . $banking_login;
if (!DEBUG) {
$this->is = ' --noninteractive';
}
$this->locale = $locale;
if (($this->bank = $this->findBank($bank_code)) === false) {
error('Bank ' . $bank_code . ' not available');
}
$this->bank_code = $bank_code;
$this->banking_login = $banking_login;
$this->banking_pin = $banking_pin;
$this->bank_user_name = $bank_user_name;
if ($account_number === false) {
$account_number = $banking_login;
}
$this->account_number = $account_number;
$this->aqcli = 'aqbanking-cli' . $this->is . ' -P "' . $this->config_dir . '/pinfile" -D "' . $this->config_dir . '/config' . '"';
if (!$this->checkConfigDir()) {
$this->makePinFile();
$this->decrypt_keyfile();
$this->addUser();
$this->checklogin();
Db::init($this->config_dir);
Db::createTables();
if ($tanmedium_id !== false) {
$this->setTanmediumId($tanmedium_id);
}
//echo "\n\n".$tanmedium_id."\n\n";
$this->getItanModes();
$this->getAccSepa();
} else {
if ($tanmedium_id !== false) {
$this->makePinFile();
$this->decrypt_keyfile();
$this->checklogin();
Db::init($this->config_dir);
$this->setTanmediumId($tanmedium_id);
}
}
$this->generateIBAN();
}
示例11: execute
function execute(WebApp $app)
{
// 载入节点数据
require_once API_ROOT . 'StorageExport.php';
$nodes = (new StorageExport())->getNodes();
$curNodeId = Conf::get('node_id');
if (!$curNodeId) {
$curNodeId = isset($_SERVER['STORAGE_NODE_ID']) ? intval($_SERVER['STORAGE_NODE_ID']) : 0;
if ($curNodeId > 0) {
Conf::set('node_id', $curNodeId);
}
}
if (!$curNodeId) {
throw new Exception('node.u_args node_id not defined');
}
// if (!isset($nodes[$curNodeId])) {
// throw new Exception('node.u_curnodeNotFound node_id='.$curNodeId);
// }
Logger::addBasic(array('node_id' => $curNodeId));
$dbConfs = Conf::get('db.conf');
foreach ($nodes as $node) {
// 设定好当前节点的数据库
$cdb = $node['node_db'];
$confs = parse_url($cdb);
if (!isset($confs['port'])) {
$confs['port'] = 3306;
}
$confs['path'] = trim($confs['path'], '/');
$confs['charset'] = 'utf8';
if (isset($confs['query'])) {
parse_str($confs['query'], $args);
if (isset($args['charset']) && $args['charset'] != 'utf8') {
$confs['charset'] = $args['charset'];
}
}
$key = 'node' . $node['node_id'];
$dbConfs['db_pool'][$key] = array('ip' => $confs['host'], 'user' => $confs['user'], 'pass' => $confs['pass'], 'port' => $confs['port'], 'charset' => $confs['charset']);
$dbConfs['dbs'][$key] = $key;
$dbConfs['db_alias'][$key] = $confs['path'];
}
Db::init($dbConfs);
Conf::set('db.conf', $dbConfs);
}
示例12: _VerifyUUID
public static function _VerifyUUID($params)
{
if (is_array($params) && isset($params['uuid']) && isset($params['email'])) {
$uuid = $params['uuid'];
$email = $params['email'];
$db = Db::init();
if ($db->query("select email from user where email=\"{$email}\"")) {
$results = $db->get_result("select uuid from user where email=\"{$email}\"");
if (isset($results[0])) {
foreach ($results as $re) {
if ($re['uuid'] === $uuid) {
$results = $db->get_result("select mid,vercode,name from udevice where email=\"{$email}\"");
return Error::getRetString(0, results);
}
}
}
} else {
return Error::getRetString(10007);
}
}
}
示例13: _Rename
/**
*
* @param params 参数列表
*/
public static function _Rename($params)
{
if (is_array($params) && isset($params["user"]) && isset($params["udid"]) && isset($params["name"])) {
$user = $params["user"];
$name = $params["name"];
$uuid = $_GET["uuid"];
$udid = $params["udid"];
$db = Db::init();
//执行主机改名
if ($db->query(<<<EOD
update user_device set name="{$name}" WHERE EXISTS(SELECT user FROM user WHERE uuid="{$uuid}" and user="{$user}" and priv=3) and user="{$user}" and udid="{$udid}";
EOD
)) {
return Error::getRetString(0);
} else {
return Error::getRetString(10016);
}
} else {
return Error::getRetString(10007);
}
}
示例14: _GetDatebase
public static function _GetDatebase($params)
{
$db = Db::init();
$res = $db->get_results("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;");
//var_dump($res);
$arr_tables = array();
//遍历表
foreach ($res as $table) {
$recodes = $db->get_results("SELECT * FROM {$table->name};");
$arr_tables["{$table->name}"] = array();
//遍历表中所有元素
foreach ($recodes as $rec) {
$arr_record = array();
//保存所有元素
foreach ($rec as $class => $value) {
$arr_record["{$class}"] = $value;
}
$arr_tables["{$table->name}"][] = $arr_record;
}
}
return json_encode($arr_tables);
}
示例15: _Enable
/**
* 使能托管模式
*
* @param params params
*/
public static function _Enable($params)
{
file_put_contents("./test.txt", "run\n", FILE_APPEND);
$db = Db::init();
$time = $params['time'];
$results = $db->get_results("select assid from assistant where time='{$time}'");
if (isset($results[0])) {
foreach ($results as $re) {
$invokes = $db->get_results("select * from assi_info where assid={$re->assid}");
if (isset($invokes[0])) {
foreach ($invokes as $invoke) {
$row = $db->get_row("select assisEn, notify from device where did='{$invoke->did}'");
//var_dump($invoke);
if ($row->assisEn == 1) {
file_put_contents("./test.txt", "actionrun\n", FILE_APPEND);
Action::run($invoke->cmdline, $invoke->mid, '慧管家');
}
}
}
}
}
}