本文整理汇总了PHP中Flight::db方法的典型用法代码示例。如果您正苦于以下问题:PHP Flight::db方法的具体用法?PHP Flight::db怎么用?PHP Flight::db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Flight
的用法示例。
在下文中一共展示了Flight::db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: is_token_valid
function is_token_valid($token)
{
$db = Flight::db();
$stmt = $db->prepare('SELECT token FROM tokens WHERE token = :token');
$stmt->bindParam(':token', $token);
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_ASSOC);
if (empty($data)) {
return false;
}
if ($data['token'] == $token) {
return true;
}
return false;
}
示例2: getUserWithEmail
/**
* Get User with Email
* @param String $email Email
* @return Object Return userobject or false
*/
public static function getUserWithEmail($email)
{
$sql = "SELECT * FROM user WHERE email = '{$email}'";
$result = Flight::db()->query($sql);
if ($result != false) {
return new user($result->fetch_assoc());
} else {
return false;
}
}
示例3: getPostWithId
/**
* Gets Post with given Id
* @param Int Id of searched post
* @return post Post with the given Id
* @todo Better error handling
*/
public static function getPostWithId($post_id)
{
$sql = "SELECT * FROM post WHERE id = '{$post_id}'";
$result = Flight::db()->query($sql);
//Todo: Better error handling
if ($result != false) {
return new post($result->fetch_assoc());
}
}
示例4: getAllPlayers
public function getAllPlayers()
{
$sql = "SELECT * FROM player ORDER BY team DESC";
$result = Flight::db()->query($sql);
$players = array();
while ($row = $result->fetch_assoc()) {
$players[] = new player($row);
}
return $players;
}
示例5: delete
public function delete()
{
Flight::db()->begin_transaction();
$sql = "DELETE FROM events WHERE id = '{$this->id}'";
$result = Flight::db()->query($sql);
if ($result == false) {
Flight::db()->rollback();
return false;
}
Flight::db()->commit();
return true;
}
示例6: validate
public function validate($model, $inputs, $update = false)
{
$rules = $model::$validate;
$error = false;
$response = array();
foreach ($inputs as $key => $input) {
if (array_key_exists($key, $rules)) {
$rule = $rules[$key];
$response[$key] = array("value" => $input, "name" => $key);
if (empty($input) && $rule['required'] == true) {
$response[$key]['type'] = "missing";
$error = true;
continue;
}
if (isset($rule['unique']) && $rule['unique'] == true && $update == false) {
$sql = "SELECT * FROM {$model} WHERE {$key} = '{$input}'";
$result = Flight::db()->query($sql);
if ($result->num_rows > 0) {
$response[$key]['type'] = 'not unique';
$error = true;
continue;
}
}
$response[$key] = array("value" => $input, "name" => $key);
switch ($rule['type']) {
case "email":
if (!filter_var($input, FILTER_VALIDATE_EMAIL)) {
$response[$key]['type'] = "invalid";
$error = true;
}
break;
case "int":
if (!filter_var($input, FILTER_VALIDATE_INT)) {
$response[$key]['type'] = "invalid";
$error = true;
}
break;
case "text":
if (!preg_match('/^[A-Za-z]+$/', $input)) {
$response[$key]['type'] = "invalid";
$error = true;
}
break;
}
}
}
return $error == true ? $response : true;
}
示例7: login
public function login()
{
$response = Flight::util()->validate("auth", Flight::request()->data);
if (is_array($response)) {
Flight::util()->render('login', array('error' => $response));
return;
}
$email = Flight::request()->data->email;
$password = Flight::request()->data->password;
$sql = "SELECT * FROM user WHERE email = '{$email}'";
$result = Flight::db()->query($sql);
if ($result == false) {
Flight::util()->render('login', array('error_string' => true));
return;
}
$row = $result->fetch_assoc();
if (password_verify($password, $row['password'])) {
$_SESSION['user'] = new user($row);
Flight::redirect('/teams');
} else {
Flight::util()->render('login', array('error_string' => true));
return;
}
}
示例8: array
require 'vendor/autoload.php';
require 'EasyBlogDBInterface.php';
include 'MyFuncs.php';
Flight::register('db', 'MyDBInterface', array('localhost', 'EasyBlog', 'root', 'root'));
session_start();
//главная страница
Flight::route('/(\\?p=@p)', function ($p) {
$s_login = SetLogin();
//gettin page index
$page = 1;
if ($p > 1) {
$page = $p;
}
$postselector = ($page - 1) * 5;
$posts = Flight::db()->GetPosts($postselector, 5);
$postscount = Flight::db()->CountPosts();
$pages_count = ceil($postscount / 5);
Flight::render('home.php', array('headertext' => 'Мой летучий блог', 'authorname' => $s_login, 'footertext' => '@ProgForce forever'), 'home_page_content');
Flight::render('post.php', array('posts' => $posts), 'posts_block');
Flight::render('page_hyperlinks.php', array('pages_count' => $pages_count, 'current_page' => $page), 'pages_n_links');
Flight::render('auth_view.php', null, 'auth_view');
Flight::render('home_layout.php', null);
});
Flight::route('/exit', function () {
session_destroy();
Flight::redirect('/');
});
Flight::route('/auth/', function () {
Flight::render('auth.php', null);
});
/*Flight::route('POST /authconfirm/', function()
示例9: array
<?php
// Includes
require 'flight/Flight.php';
require 'classes/auth.class.php';
require 'classes/config.class.php';
require 'languages/en.php';
require 'database.php';
// Settings
Flight::set('lang', $lang);
Flight::set('flight.log_errors', true);
Flight::set('flight.views.path', 'views/');
// Register classes
Flight::register('db', 'PDO', array("mysql:host={$db_host};dbname={$db_name}", $db_user, $db_pass));
Flight::register('config', 'Config', array(Flight::db()));
Flight::register('auth', 'Auth', array(Flight::db(), Flight::config()));
// Set Timezone
date_default_timezone_set(Flight::config()->site_timezone);
// Check if user is logged in
if (Flight::request()->cookies->{Flight::config()->cookie_name} == false) {
Flight::set('loggedin', false);
} else {
if (Flight::auth()->checkSession(Flight::request()->cookies->{Flight::config()->cookie_name})) {
Flight::set('loggedin', true);
$uid = Flight::auth()->getSessionUID(Flight::request()->cookies->{Flight::config()->cookie_name});
Flight::set('userdata', Flight::auth()->getUser($uid));
} else {
Flight::set('loggedin', false);
setcookie(Flight::config()->cookie_name, "", time() - 3600, Flight::config()->cookie_path, Flight::config()->cookie_domain, Flight::config()->cookie_secure, Flight::config()->cookie_http);
}
}
示例10: projects
<?php
try {
$db = Flight::db();
$db->exec('CREATE TABLE projects(
id INTEGER PRIMARY KEY,
title VARCHAR(255) NOT NULL,
date DATE,
link TEXT,
description TEXT,
tags VARCHAR(255)
);');
} catch (PDOException $e) {
echo $e->getMessage();
}
示例11: getEventWithId
public function getEventWithId($id)
{
$sql = "SELECT * FROM events WHERE id = '{$id}'";
$result = Flight::db()->query($sql);
return new event($result->fetch_assoc());
}
示例12: query
public static function query($statement)
{
$db = \Flight::db();
return $db->query($statement);
}
示例13: update
/**
* Update user
* @return Mysqliresult Result from query
*/
public function update()
{
$sql = "UPDATE user SET prename = '{$this->prename}', surname = '{$this->surname}', bio = '" . nl2br($this->bio) . "', email = '{$this->email}', password = '{$this->password}' WHERE id = '{$this->id}'";
$result = Flight::db()->query($sql);
return $result;
}
示例14: snippet
static function snippet()
{
$data = Flight::request()->data;
$mode = $data["mode"];
if ($mode === "get") {
$sql = "SELECT * FROM snippets WHERE LOWER(identifier) LIKE LOWER(?)";
$sth = Flight::db()->prepare($sql);
$sth->bindParam(1, $data["identifier"]);
$sth->execute();
$res = $sth->fetchAll(PDO::FETCH_ASSOC);
if (count($res) == 0) {
Flight::error();
}
echo Flight::json($res[0]);
} elseif ($mode === "exists") {
$sql = "SELECT * FROM snippets WHERE LOWER(identifier) LIKE LOWER(?)";
$sth = Flight::db()->prepare($sql);
$sth->bindParam(1, $data["identifier"]);
$sth->execute();
$res = $sth->fetchAll(PDO::FETCH_ASSOC);
if (count($res) !== 0) {
Flight::error();
} else {
echo "";
}
} elseif ($mode === "new") {
$sql = "SELECT * FROM snippets WHERE LOWER(identifier) LIKE LOWER(?)";
$sth = Flight::db()->prepare($sql);
$sth->bindParam(1, $data["identifier"]);
$sth->execute();
$res = $sth->fetchAll();
if (count($res) !== 0) {
Flight::error();
}
$jwt = JWTHelper::authenticate(apache_request_headers());
$sql = "INSERT INTO snippets(identifier,name,author,version,code) VALUES(?,?,?,?,?)";
$sth = Flight::db()->prepare($sql);
$sth->bindParam(1, $data["identifier"]);
$sth->bindParam(2, $data["name"]);
$sth->bindParam(3, $jwt->data->userName);
$sth->bindParam(4, $data["version"]);
$sth->bindParam(5, $data["code"]);
$sth->execute();
} elseif ($mode === "delete") {
$sql = "SELECT * FROM snippets WHERE LOWER(identfier) LIKE LOWER(?)";
$sth = Flight::db()->prepare($sql);
$sth->bindParam(1, $data["identifier"]);
$sth->execute();
$res = $sth->fetchAll();
if (count($res) !== 1) {
Flight::error();
}
$jwt = JWTHelper::authenticate(apache_request_headers());
$sql = "DELETE FROM snippets WHERE LOWER(identifier) LIKE LOWER(?)";
$sth = Flight::db()->prepare($sql);
$sth->bindParam(1, $data["identifier"]);
$sth->execute();
}
}
示例15: getUserWithId
public function getUserWithId($id)
{
$sql = "SELECT * FROM user WHERE id = '{$id}'";
$result = Flight::db()->query($sql);
return new user($result->fetch_assoc());
}