• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP core\Database类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中core\Database的典型用法代码示例。如果您正苦于以下问题:PHP Database类的具体用法?PHP Database怎么用?PHP Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Database类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: clearTables

 private static function clearTables(\Core\Database $db)
 {
     $clearScript = new \Helpers\TablesClearScript();
     foreach ($clearScript as $statement) {
         $db->exec($statement, array());
     }
 }
开发者ID:anddorua,项目名称:boardroom,代码行数:7,代码来源:BookControllerTest.php


示例2: getRepublicas

 /**
  * @param float $latitude
  * @param float $longitude
  * @param $radio
  */
 public static function getRepublicas($latitude, $longitude, $radius, Database &$database)
 {
     $latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
     $longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
     $radius = filter_var($radius, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
     //Haversine formula
     $query = $database->prepare('
         SELECT *, (6371 * acos(
             cos(radians( :latitude )) * cos(radians(latitude)) *
             cos(radians(longitude) - radians( :longitude )) + 
             sin(radians( :latitude )) * sin(radians(latitude))
         ))
         AS distance
         FROM republicas
         HAVING distance < :radius
         ORDER BY distance
     ');
     $query->bindParam(':latitude', $latitude);
     $query->bindParam(':longitude', $longitude);
     $query->bindParam(':radius', $radius);
     $query->execute();
     $json = array();
     while ($item = $query->fetch(Database::FETCH_ASSOC)) {
         $json[] = $item;
     }
     return json_encode($json);
 }
开发者ID:engenhariaSI,项目名称:pingpONG,代码行数:32,代码来源:Republicas.php


示例3: get

 /**
  * Static method get
  *
  * @param  array $group
  * @return \helpers\database
  */
 public static function get($group = null)
 {
     // Determining if exists or it's not empty, then use default group defined in config
     $group = !$group ? array('type' => DB_TYPE, 'host' => DB_HOST, 'name' => DB_NAME, 'user' => DB_USER, 'pass' => DB_PASS, 'port' => DB_PORT) : $group;
     // Group information
     $type = $group['type'];
     $host = $group['host'];
     $name = $group['name'];
     $user = $group['user'];
     $pass = $group['pass'];
     $port = $group['port'];
     // ID for database based on the group information
     $id = "{$type}.{$host}.{$port}.{$name}.{$user}.{$pass}";
     // Checking if the same
     if (isset(self::$instances[$id])) {
         return self::$instances[$id];
     }
     try {
         // I've run into problem where
         // SET NAMES "UTF8" not working on some hostings.
         // Specifiying charset in DSN fixes the charset problem perfectly!
         $instance = new Database("{$type}:host={$host};port={$port};dbname={$name};charset=utf8", $user, $pass);
         $instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         // Setting Database into $instances to avoid duplication
         self::$instances[$id] = $instance;
         return $instance;
     } catch (PDOException $e) {
         //in the event of an error record the error to ErrorLog.html
         Logger::newMessage($e);
         Logger::customErrorMsg();
     }
 }
开发者ID:ayrtonmonier,项目名称:babita,代码行数:38,代码来源:Database.php


示例4: getAll

 public function getAll(\Core\Database $db)
 {
     $recs = $db->fetchAllAssoc("select * from rooms", array());
     $result = array();
     for ($i = 0; $i < count($recs); $i++) {
         $result[] = new \Application\RoomItem($recs[$i]);
     }
     return $result;
 }
开发者ID:anddorua,项目名称:boardroom,代码行数:9,代码来源:RoomItem.php


示例5: makeUpdateQuery

 protected function makeUpdateQuery($table_name, $fields_to_save, array $where_condition, \Core\Database $db)
 {
     $value_equation_list_imploded = $this->makeEquationString(',', $fields_to_save);
     $value_list = $this->makeValueVarArray($fields_to_save);
     $sql = "update {$table_name} set {$value_equation_list_imploded} where " . $this->makeEquationString(' and ', $where_condition);
     $value_list = array_merge($value_list, $this->makeValueVarArray($where_condition));
     //error_log("\nSQL:" . print_r($sql, true) . "\nvalues:" . print_r($value_list, true), 3, "my_errors.txt");
     return $db->exec($sql, $value_list);
 }
开发者ID:anddorua,项目名称:boardroom,代码行数:9,代码来源:ObjectMapper.php


示例6: getUserId

 public static function getUserId($username, $password)
 {
     $result = Database::getInstance()->prepare("SELECT id FROM `users` where `username` = :username AND `password`=:password OR `email`=:username AND `password`=:password");
     $result->execute(array(':username' => $username, ':password' => $password));
     $row = $result->fetch(PDO::FETCH_ASSOC);
     return $row['id'];
 }
开发者ID:saqbest,项目名称:test_project,代码行数:7,代码来源:App.php


示例7: GetUseUserCount

 /**
  * Get use user count
  * @return int
  */
 public static function GetUseUserCount()
 {
     $statement = Database::prepare("SELECT count(*) FROM member WHERE lastConnTime > 0");
     $statement->execute();
     $count = $statement->fetch(\PDO::FETCH_NUM);
     return $count[0] == null ? 0 : $count[0];
 }
开发者ID:beautifultable,项目名称:shadowsocks-panel,代码行数:11,代码来源:Ana.php


示例8: __construct

 /**
  * Create a new instance of the database helper.
  */
 public function __construct()
 {
     /**
      * connect to PDO here.
      */
     $this->db = \Core\Database::get();
 }
开发者ID:krishnasrikanth,项目名称:smvc-php7,代码行数:10,代码来源:Model.php


示例9: queryUrl

 public static function queryUrl($url)
 {
     $stm = Database::sql('SELECT `id`, `alias`, `url`, `status`, `add_time`, `click_num` FROM `url_list` WHERE `url`=?');
     $stm->bindValue(1, $url, Database::PARAM_STR);
     $stm->execute();
     return $stm->fetchObject(__CLASS__);
 }
开发者ID:sendya,项目名称:shortUrl,代码行数:7,代码来源:Url.php


示例10: __construct

 /**
  * Create a new PageData object.
  * @param string $tableName Target table name
  * @param string $extras Such as where statement or order statement
  * @param array $column Column names needs to be fetch
  */
 public function __construct($tableName, $extras = '', $column = array('*'))
 {
     $columns = '`' . implode('`, `', $column) . '`';
     $this->countQuery = Database::getInstance()->prepare("SELECT COUNT(*) FROM `{$tableName}` {$extras}");
     $this->query = Database::getInstance()->prepare("SELECT {$columns} FROM `{$tableName}` {$extras} LIMIT :pageDataStart,:pageDataRPP");
     if ($_GET['page']) {
         $this->setPage($_GET['page']);
     }
 }
开发者ID:sendya,项目名称:mcSkin,代码行数:15,代码来源:PageData.php


示例11: save

 public function save($mode = self::SAVE_AUTO)
 {
     $map = array();
     $reflection = new ReflectionObject($this);
     $reflectionProp = $reflection->getProperties(ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PUBLIC);
     foreach ($reflectionProp as $property) {
         if (strpos($property->getDocComment(), '@ignore')) {
             continue;
         }
         $propertyName = $property->getName();
         if ($propertyName == 'primaryKey') {
             continue;
         }
         if ($property->isProtected()) {
             $property->setAccessible(true);
         }
         $propertyValue = $property->getValue($this);
         $map[$propertyName] = $propertyValue;
     }
     $primaryKey = $this->getPrimaryKeyName($reflection);
     $identifier = $map[$primaryKey];
     unset($map[$primaryKey]);
     $tableName = $this->getTableName($reflection);
     if ($mode == self::SAVE_UPDATE || $identifier && $mode != self::SAVE_INSERT) {
         $sql = "UPDATE `{$tableName}` SET ";
         foreach ($map as $key => $value) {
             $sql .= "`{$key}` = :{$key},";
         }
         $sql = rtrim($sql, ',');
         $sql .= " WHERE {$primaryKey} = :id";
         $statement = Database::getInstance()->prepare($sql);
         $statement->bindValue(':id', $identifier);
         foreach ($map as $key => $value) {
             $statement->bindValue(":{$key}", $value);
         }
     } else {
         $sql = "INSERT INTO `{$tableName}` SET ";
         foreach ($map as $key => $value) {
             $sql .= "`{$key}` = :{$key},";
         }
         $sql = rtrim($sql, ',');
         $statement = Database::getInstance()->prepare($sql);
         foreach ($map as $key => $value) {
             $statement->bindValue(":{$key}", $value);
         }
     }
     $statement->execute();
     if (!$identifier) {
         $insertId = Database::getInstance()->lastInsertId();
         if ($insertId) {
             $reflection->getProperty($primaryKey)->setValue($this, $insertId);
         }
     }
 }
开发者ID:sendya,项目名称:mcSkin,代码行数:54,代码来源:Model.php


示例12: save

 /**
  * @param (int|string)[] $answers
  *
  * @return boolean
  */
 public static function save(array $answers, Database &$database)
 {
     $options = array('dificuldade' => FILTER_SANITIZE_STRING, 'explicacao_dificuldade' => FILTER_SANITIZE_STRING, 'encontrou' => FILTER_SANITIZE_STRING, 'aluno_EACH' => FILTER_SANITIZE_STRING, 'indicaria' => FILTER_SANITIZE_STRING, 'referencia' => FILTER_SANITIZE_STRING, 'nota_design' => FILTER_SANITIZE_NUMBER_INT, 'nota_funcionalidades' => FILTER_SANITIZE_NUMBER_INT, 'nota_acessibilidade' => FILTER_SANITIZE_NUMBER_INT, 'nota_insercao_reps' => FILTER_SANITIZE_NUMBER_INT, 'info_adicional' => FILTER_SANITIZE_STRING);
     $answers = filter_var_array($answers, $options);
     $query = $database->prepare('
         INSERT INTO feedback (
             dificuldade, explicacao_dificuldade, encontrou, aluno_EACH,
             indicaria, referencia, nota_design, nota_funcionalidades,
             nota_acessibilidade, nota_insercao_reps, info_adicional
         ) VALUES (
             :dificuldade, :explicacao_dificuldade, :encontrou, :aluno_EACH,
             :indicaria, :referencia, :nota_design, :nota_funcionalidades,
             :nota_acessibilidade, :nota_insercao_reps, :info_adicional
         )
     ');
     do {
         $query->bindParam(':' . key($answers), current($answers));
     } while (next($answers) !== false);
     return $query->execute();
 }
开发者ID:engenhariaSI,项目名称:pingpONG,代码行数:25,代码来源:Feedback.php


示例13: run

 public function run()
 {
     // 清理一个月前的数据
     $mon = time() - 2592000;
     $stn = Database::sql('DELETE FROM `card` WHERE add_time<? AND status=0');
     $stn->bindValue(1, $mon, Database::PARAM_INT);
     $stn->execute();
     $stn = Database::sql("DELETE FROM `invite` WHERE dateLine<? AND status=1");
     $stn->bindValue(1, $mon, Database::PARAM_INT);
     $stn->execute();
 }
开发者ID:sendya,项目名称:shadowsocks-panel,代码行数:11,代码来源:ClearLogs.php


示例14: execute

 /**
  * Migrate current database
  * @param $dropTable bool drop the table
  */
 public function execute($dropTable = false)
 {
     $this->database = Database::getInstance();
     $modelDir = "Application/Model";
     $file = opendir($modelDir);
     // there is fileName
     while (($fileName = readdir($file)) !== false) {
         if (substr($fileName, -4) == ".php") {
             $this->migrateTable($modelDir . "/" . $fileName, $dropTable);
         }
     }
 }
开发者ID:phuongjolly,项目名称:ECard,代码行数:16,代码来源:Migration.php


示例15: getById

 public static function getById($id)
 {
     try {
         $connection = Database::instance();
         $sql = "SELECT * from usuarios WHERE id = ?";
         $query = $connection->prepare($sql);
         $query->bindParam(1, $id, \PDO::PARAM_INT);
         $query->execute();
         return $query->fetch();
     } catch (\PDOException $e) {
         print "Error!: " . $e->getMessage();
     }
 }
开发者ID:vmendieta,项目名称:PFinal-WebUCA2015,代码行数:13,代码来源:User.php


示例16: getUserPassword

 public static function getUserPassword($user_name, $password)
 {
     try {
         $connection = Database::instance();
         $sql = "SELECT * from usuarios WHERE nombre_usuario = ? AND clave_usuario = ?";
         $query = $connection->prepare($sql);
         $query->bindParam(2, $user_name, $password, \PDO::PARAM_INT);
         $query->execute();
         return $query->fetch();
     } catch (\PDOException $e) {
         print "Error!: " . $e->getMessage();
     }
 }
开发者ID:andrescefe,项目名称:SAPP,代码行数:13,代码来源:Login.php


示例17: login

 /**
  * @static
  * @param string $email
  * @param string $password
  * @param string $location URL you want to redirect user to
  *
  * @return boolean
  */
 public static function login($email, $password, Database &$database)
 {
     $email = filter_var($email, FILTER_SANITIZE_EMAIL);
     $validEmail = (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
     if (!$validEmail) {
         return false;
     }
     $query = $database->prepare('
         SELECT id, password, salt FROM users WHERE email = :email
     ');
     $query->bindParam(':email', $email, Database::PARAM_STR);
     $query->execute();
     $success = false;
     if ($query->rowCount() == 1) {
         $result = $query->fetch(Database::FETCH_ASSOC);
         $passwordHash = hash('sha512', $result['salt'] . $password);
         $success = $result['password'] == $passwordHash;
         if ($success) {
             $_SESSION['user_id'] = $result['id'];
         }
     }
     return $success;
 }
开发者ID:engenhariaSI,项目名称:pingpONG,代码行数:31,代码来源:Authentication.php


示例18: emailFind

 public static function emailFind($email)
 {
     $db = Database::connect();
     //TODO: Change to prepared statement
     if ($stmt = $db->query("SELECT id FROM Users WHERE email = '{$email}'")) {
         if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
             return new self($data["id"]);
         } else {
             //No user with that email
             return false;
         }
     } else {
         throw \Exception\DatabaseError::build($db);
     }
 }
开发者ID:adibradfield,项目名称:tasker,代码行数:15,代码来源:User.php


示例19: execute

 /**
  * Execute a PDO prepare with execute
  * 
  * @param $query
  *            The query to execute
  * @param array $params
  *            The query parameters
  * @return An array with the results
  */
 public static function execute($query, $params = [])
 {
     // Preparing the query with the database instance
     $results = Database::getInstance()->prepare($query);
     // Executing the query with the given parameters
     $results->execute($params);
     // Fetching the results
     $results = $results->fetchAll(\PDO::FETCH_OBJ);
     // Checking them
     if (count($results) < 2) {
         $results = current($results);
     }
     // Returning them
     return $results;
 }
开发者ID:Halvra,项目名称:OpenAuth-Server,代码行数:24,代码来源:Queries.php


示例20: validate

 function validate($username, $password)
 {
     $session = Node::getOne(array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_SESSION, 'username' => Database::escapeValue($username)));
     $res = Session::validate($username, $password, $this->request()->fingerprint());
     if (is_int($res)) {
         switch ($res) {
             case Session::ERR_MISMATCH:
                 throw new ServiceException('Username and password mismatch.', $res);
                 break;
             case Session::ERR_EXISTS:
                 throw new ServiceException('Session already exists.', $res);
                 break;
         }
     }
     return $res;
 }
开发者ID:Victopia,项目名称:prefw,代码行数:16,代码来源:sessions.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP core\Model类代码示例发布时间:2022-05-23
下一篇:
PHP core\Controller类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap