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

PHP SelectQuery类代码示例

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

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



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

示例1: search

 public static function search(TableCtl $controller, $term, $filter = false)
 {
     $object = call_user_func(array(get_class($controller), 'getObject'));
     if (!$object) {
         return false;
     }
     $terms = preg_split('/[ ,]/', $term);
     if (!count($terms)) {
         return false;
     }
     //Check for results containing the word
     $search = array();
     foreach ($terms as $oneTerm) {
         $search[] = '`word` LIKE CONCAT("%", ?, "%")';
     }
     //Check for results with the exact word
     $search[] = '`word` IN (' . implode(', ', array_fill(0, count($terms), '?')) . ')';
     $search = '(' . implode(') OR (', $search) . ')';
     $params = array_merge(array($object->getSource()), $terms, $terms);
     $query = new SelectQuery(get_called_class());
     $query->field('DISTINCT `' . $object->getMeta('table') . '`.*')->leftJoin(get_class($controller), '`' . $object->getMeta('table') . '`.`' . $object->getMeta('id_field') . '` = `table_id`')->filter('`table` = ?')->filter($search)->order('`count` DESC, `sequence`');
     if ($filter) {
         if (is_array($filter)) {
             foreach ($filter as $one_fil) {
                 $query->filter($one_fil);
             }
         } else {
             $query->filter($filter);
         }
     }
     $result = $query->fetchAll($params);
     return $result;
 }
开发者ID:jrgns,项目名称:backend-php,代码行数:33,代码来源:BackendSearch.obj.php


示例2: getConnection

 public function getConnection()
 {
     $q = new SelectQuery();
     $this->assertNull($q->getConnection());
     $q->setPeer(Job::getPeer());
     $this->assertClass($q->getConnection(), 'net.xp_framework.unittest.rdbms.mock.MockConnection');
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:7,代码来源:QueryTest.class.php


示例3: hook_query_rules_autotag_terms_alter

/**
 * Alter the term DB query.
 *
 * @param SelectQuery $query
 *   The query object ot alter.
 */
function hook_query_rules_autotag_terms_alter($query)
{
    // Join the original term query from rules_autotag with our field table to
    // exclude terms that should not be tagged.
    $query->leftJoin('field_data_field_dont_autotag', 'fd', "t.tid = fd.entity_id AND fd.entity_type = 'taxonomy_term'");
    $query->condition(db_or()->condition('fd.field_dont_autotag_value', NULL)->condition('fd.field_dont_autotag_value', '1', '<>'));
}
开发者ID:agroknow,项目名称:agreri,代码行数:13,代码来源:rules_autotag.api.php


示例4: check

 public static function check()
 {
     if (!empty($_COOKIE['remembered'])) {
         $query = new SelectQuery('PersistUser');
         $persist = $query->filter('MD5(CONCAT(`id`, `user_id`, `random`)) = :hash')->fetchAssoc(array(':hash' => $_COOKIE['remembered']));
         if ($persist) {
             //Get User
             $User = self::getObject('BackendUser');
             if (!$User instanceof DBObject) {
                 return false;
             }
             $query = BackendUser::getQuery();
             $query->filter('`backend_users`.`id` = :id');
             $params = array(':id' => $persist['user_id']);
             $User->read(array('query' => $query, 'parameters' => $params, 'mode' => 'object'));
             if ($User->object) {
                 $_SESSION['BackendUser'] = $User->object;
                 //Remove, and reremember
                 if (self::remember($User->object)) {
                     $query = new DeleteQuery('PersistUser');
                     $query->filter('`id` = :id')->limit(1);
                     $query->execute(array(':id' => $persist['id']));
                 } else {
                     Backend::addError('Could not reremember');
                 }
                 return $User->object;
             } else {
                 //Backend::addError('Invalid remembered user');
             }
         }
     }
     return false;
 }
开发者ID:jrgns,项目名称:backend-php,代码行数:33,代码来源:PersistUser.obj.php


示例5: getToJoin

 /**
  * @return string
  */
 private function getToJoin()
 {
     if ($this->tojoin instanceof SelectQuery || $this->tojoin instanceof UnionQuery) {
         return " (" . $this->tojoin->get(false) . ")";
     } else {
         return " " . $this->tojoin;
     }
 }
开发者ID:Warsaalk,项目名称:Plinth,代码行数:11,代码来源:JoinQuery.php


示例6: joinHelperTable

 /**
  * @return SelectQuery
  **/
 protected function joinHelperTable(SelectQuery $query)
 {
     $uc = $this->container;
     if (!$query->hasJoinedTable($uc->getHelperTable())) {
         $query->join($uc->getHelperTable(), Expression::eq(new DBField($uc->getParentTableIdField(), $uc->getDao()->getTable()), new DBField($uc->getChildIdField(), $uc->getHelperTable())));
     }
     return $query->andWhere(Expression::eq(new DBField($uc->getParentIdField(), $uc->getHelperTable()), new DBValue($uc->getParentObject()->getId())));
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:11,代码来源:ManyToManyLinkedWorker.class.php


示例7: action_create

    public function action_create()
    {
        if (is_post()) {
            $parameters = get_previous_parameters();
            $object = new CommentObj();
            $object = $object->fromRequest();
            $object['foreign_id'] = empty($object['foreign_id']) ? reset($parameters) : $object['foreign_id'];
            $object['foreign_table'] = empty($object['foreign_table']) ? table_name(get_previous_area()) : $object['foreign_table'];
            //If we don't have a logged in user, create a dummy account
            if (!BackendUser::check()) {
                $query = new SelectQuery('BackendUser');
                $query->filter('`email` = :email');
                if ($old_user = Controller::getVar('user')) {
                    $existing_user = $query->fetchAssoc(array(':email' => $old_user['email']));
                }
                switch (true) {
                    case $existing_user && $existing_user['confirmed'] && $existing_user['active']:
                        //Attribute quote to user? Seems risque, actually, if I know a user's email address, I can just attribute to him. Auth first
                        Backend::addError('Comment not added. Please login first');
                        return false;
                        break;
                    case $existing_user && !$existing_user['confirmed'] && $existing_user['active']:
                        //Unregistered user commented before
                        $object['user_id'] = $existing_user['id'];
                        break;
                    default:
                    case !$existing_user:
                        $user_data = array('name' => $old_user['name'], 'surname' => '', 'email' => $old_user['email'], 'website' => $old_user['website'], 'username' => $old_user['email'], 'password' => get_random(), 'confirmed' => 0, 'active' => 1);
                        $user = self::getObject('BackendUser');
                        if ($user->create($user_data)) {
                            $object['user_id'] = $user->array['id'];
                            $url = SITE_LINK . '/?q=backend_user/confirm/' . $user->array['salt'];
                            $app_name = ConfigValue::get('Title');
                            $message = <<<END
Hi {$user->array['name']}!

Thank you for your comment on {$app_name}. An account has automatically been created for you. To activate it, please click on the following link:

{$url}

Please note that you don't need to do this for your comments to show, but this account will be deleted if it isn't confirmed in a weeks time.

Regards
END;
                            send_email($user->array['email'], 'Thank you for your comment.', $message);
                        } else {
                            Backend::addError('Could not create user to add Comment');
                            return false;
                        }
                        break;
                }
            }
            $object = array_filter($object, create_function('$var', 'return !is_null($var);'));
            Controller::setVar('obj', $object);
        }
        return parent::action_create();
    }
开发者ID:jrgns,项目名称:backend-php,代码行数:57,代码来源:Comment.obj.php


示例8: action_filter

 public function action_filter($pageId = 1)
 {
     $query = new SelectQuery('BackendRequest');
     $query->setFields(array('user_id', 'ip', 'user_agent', 'mode', 'request', 'query', 'COUNT(id) AS `occured`', 'MAX(`added`) AS `last_occured`'));
     $query->setGroup(array('user_id', 'ip', 'user_agent', 'mode', 'request', 'query'));
     $params = $queryFilter = array();
     $parameters = Controller::getVar('params');
     $sort = Controller::getVar('sort');
     if (!empty($parameters['userId'])) {
         $queryFilter[] = 'user_id = :userId';
         $params[':userId'] = $parameters['userId'];
     }
     if (!empty($parameters['query'])) {
         $queryFilter[] = "query LIKE('%{$parameters['query']}%')";
     }
     if (!empty($parameters['ip'])) {
         $queryFilter[] = "ip LIKE('%{$parameters['ip']}%')";
     }
     if (!empty($parameters['user_agent'])) {
         $queryFilter[] = "user_agent LIKE('%{$parameters['user_agent']}%')";
     }
     $query->filter($queryFilter);
     $count = 10;
     if (!empty($sort['field'])) {
         $query->setOrder(array($sort['field'] . '  ' . $sort['order']));
     }
     if ($pageId == 1) {
         $start = 0;
     } elseif ($pageId == 0) {
         $start = false;
         $count = false;
     } else {
         $start = floor(($pageId - 1) * $count);
     }
     $pager = array();
     if ($start === 'all') {
         $limit = 'all';
     } else {
         if ($start || $count) {
             $limit = "{$start}, {$count}";
         } else {
             $limit = false;
         }
     }
     $query->limit($limit);
     $items = $query->fetchAll($params);
     $totalItems = $query->getCount($params);
     $pager = '';
     if ($start || $count) {
         $pager = array('currentPage' => $pageId, 'itemCount' => count($items), 'itemTotal' => $totalItems, 'totalPages' => round(($totalItems - 1) / $count, 0));
     }
     $retArray['pager'] = $pager;
     $retArray['data'] = $items;
     $retArray['params'] = $parameters;
     $retArray['sort'] = $sort;
     return $retArray;
 }
开发者ID:jrgns,项目名称:backend-php,代码行数:57,代码来源:BackendRequest.obj.php


示例9: action_check_defines

 public function action_check_defines()
 {
     if (!Component::isActive('BackendError')) {
         return false;
     }
     $query = new SelectQuery('BackendError');
     $query->distinct()->field('query')->filter("`string` LIKE 'Undefined index: %'")->filter("`file` LIKE '%\\\\Render.obj.php(%) : eval()\\'d code'")->filter("`query` LIKE 'a_p_i/define/%'");
     return $query->fetchAll(array(), array('column' => 0));
 }
开发者ID:jrgns,项目名称:backend-php,代码行数:9,代码来源:API.obj.php


示例10: from

 /** Create SELECT query from $table
  * @param string $table  db table name
  * @param integer $primaryKey  return one row by primary key
  * @return SelectQuery
  */
 public function from($table, $primaryKey = null)
 {
     $query = new SelectQuery($this, $table);
     if ($primaryKey) {
         $tableTable = $query->getFromTable();
         $tableAlias = $query->getFromAlias();
         $primaryKeyName = $this->structure->getPrimaryKey($tableTable);
         $query = $query->where("{$tableAlias}.{$primaryKeyName}", $primaryKey);
     }
     return $query;
 }
开发者ID:srgandawali,项目名称:Package,代码行数:16,代码来源:FluentPDO.php


示例11: process

 public function process(\SelectQuery $query)
 {
     $result = $query->limit($this->options['limit'])->offset($this->options['page'] * $this->options['limit'])->fetchAll();
     $this->count = count($result);
     // Check to see if total is equal to our limit and check for the real total
     if ($this->options['page'] || $this->count == $this->options['limit']) {
         $this->total = (int) $query->limit(null)->offset(null)->select(null)->select('COUNT(*)')->fetchColumn();
     } else {
         $this->total = $this->count;
     }
     return $result;
 }
开发者ID:ameech,项目名称:schedule-api,代码行数:12,代码来源:Paginate.php


示例12: action_display

 public function action_display($id)
 {
     $query = new SelectQuery('ContentRevision');
     $query->filter('`content_id` = :id')->order('`added` DESC');
     $revisions = $query->fetchAll(array(':id' => $id));
     $content = new ContentObj($id);
     if ($content->object) {
         $content->object->revisions = $revisions;
     } else {
         $content = false;
     }
     return $content;
 }
开发者ID:jrgns,项目名称:backend-php,代码行数:13,代码来源:ContentRevision.obj.php


示例13: cacheByQuery

 protected function cacheByQuery(SelectQuery $query, $object, $expires = Cache::EXPIRES_FOREVER)
 {
     $queryId = $query->getId();
     $semKey = $this->keyToInt($this->indexKey);
     $key = $this->makeQueryKey($query, self::SUFFIX_QUERY);
     $pool = SemaphorePool::me();
     if ($pool->get($semKey)) {
         $this->syncMap($key);
         Cache::me()->mark($this->className)->add($key, $object, $expires);
         $pool->free($semKey);
     }
     return $object;
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:13,代码来源:SmartDaoWorker.class.php


示例14: initializeForTokens

 /**
  * Initialize this object for a set of authentication tokens. Set the 
  * password to the encrypted version.
  * 
  * @param mixed $tokens
  * @return void
  * @access public
  * @since 3/1/05
  */
 function initializeForTokens($tokens)
 {
     ArgumentValidator::validate($tokens, ArrayValidatorRule::getRule());
     ArgumentValidator::validate($tokens['username'], StringValidatorRule::getRule());
     ArgumentValidator::validate($tokens['password'], StringValidatorRule::getRule());
     $this->_tokens = $tokens;
     $this->_identifier = $tokens['username'];
     // set the password to the encrypted version.
     $dbc = Services::getService("DatabaseManager");
     $dbId = $this->_configuration->getProperty('database_id');
     $passwordQuery = new SelectQuery();
     $passwordQuery->addColumn("SHA1('" . addslashes($tokens['password']) . "')", "encryptedPassword");
     $passwordResult = $dbc->query($passwordQuery, $dbId);
     $this->_tokens['password'] = $passwordResult->field("encryptedPassword");
     $passwordResult->free();
 }
开发者ID:adamfranco,项目名称:harmoni,代码行数:25,代码来源:SQLDatabaseSHA1UsernamePasswordAuthNTokens.class.php


示例15: getThemes

 /**
  * Answer an array of all of the themes known to this source
  * 
  * @return array of Harmoni_Gui2_ThemeInterface
  * @access public
  * @since 5/6/08
  */
 public function getThemes()
 {
     $themes = array();
     $query = new SelectQuery();
     $query->addTable('segue_site_theme');
     $query->addColumn('id');
     $query->addWhereEqual('fk_site', $this->getSiteId());
     $dbMgr = Services::getService("DatabaseManager");
     $result = $dbMgr->query($query, $this->databaseIndex);
     while ($result->hasNext()) {
         $row = $result->next();
         $themes[] = new Segue_Gui2_SiteTheme($this->databaseIndex, $row['id']);
     }
     $result->free();
     return $themes;
 }
开发者ID:adamfranco,项目名称:segue,代码行数:23,代码来源:SiteThemeSource.class.php


示例16: read

 public function read($options = array())
 {
     $result = parent::read($options);
     if ($result) {
         $query = new SelectQuery('Assignment');
         $query->distinct()->field('`roles`.`name`')->leftJoin('Role', '`roles`.`id` = `assignments`.`role_id`')->filter("`assignments`.`access_type` = 'users'")->filter('`assignments`.`access_id` = :user_id OR `assignments`.`access_id` = 0')->order('`roles`.`name`');
         $roles = $query->fetchAll(array(':user_id' => $this->getMeta('id')), array('column' => 0));
         $roles = empty($roles) ? array() : $roles;
         if ($this->object) {
             $this->object->roles = $roles;
         }
         if ($this->array) {
             $this->array['roles'] = $roles;
         }
     }
     return $result;
 }
开发者ID:jrgns,项目名称:backend-php,代码行数:17,代码来源:BackendUserObj.obj.php


示例17: PersistentOrderedSet

 /**
  * Constructor.
  * @param object Id $setId The Id of this set.
  * @param integer $dbIndex The index of the database connection which has
  * 		tables in which to store the set.
  */
 function PersistentOrderedSet($setId, $dbIndex)
 {
     parent::OrderedSet($setId);
     ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
     // Create our internal array
     $this->_dbIndex = $dbIndex;
     // populate our array with any previously stored items.
     $query = new SelectQuery();
     $query->addColumn("item_order", "item_order");
     $query->addColumn("item_id", "item_id");
     $query->addTable("sets");
     $query->addWhere("id = '" . addslashes($this->_setId->getIdString()) . "'");
     $query->addOrderBy("item_order");
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, $this->_dbIndex);
     $i = 0;
     $oldItems = array();
     while ($result->hasMoreRows()) {
         // Add the items to our array
         $this->_items[$i] = $result->field("item_id");
         // Store an array of the order-key/value relationships to reference
         // when updating any inconsistancies in order numbering.
         $oldItems[$result->field("item_order")] = $result->field("item_id");
         $i++;
         $result->advanceRow();
     }
     $result->free();
     // Make sure that we have our set is filled from 0 to count()
     reset($oldItems);
     $this->_updateOrders($oldItems);
 }
开发者ID:adamfranco,项目名称:harmoni,代码行数:37,代码来源:PersistentOrderedSet.class.php


示例18: getMatching

 /**
  * Since the agent manager package already has support for filtering agents and
  * groups from traversal info iterators, return our search results as traversal
  * info.
  * 
  * @param string $criteria
  * @return TraversalInfoIterator
  * @access protected
  * @since 1/31/08
  */
 protected function getMatching($criteria)
 {
     $dbc = Services::getService('DatabaseManager');
     $idMgr = Services::getService('Id');
     $query = new SelectQuery();
     $query->addTable('agent_properties');
     $query->addColumn("DISTINCT fk_object_id", "agent_id");
     $query->addWhereLike("property_value", str_replace('*', '%', $criteria));
     $info = array();
     $result = $dbc->query($query, $this->databaseIndex);
     while ($result->hasNext()) {
         $row = $result->next();
         if (!strlen($row['agent_id'])) {
             throw new OperationFailedException("No valid agent_id found in row for query: " . $query->asString());
         }
         $info[] = new HarmoniTraversalInfo($idMgr->getId($row['agent_id']), '', 0);
     }
     return new HarmoniTraversalInfoIterator($info);
 }
开发者ID:adamfranco,项目名称:harmoni,代码行数:29,代码来源:AgentPropertiesSearch.class.php


示例19: getPartStructureIdsForTagGeneration

 /**
  * Answer the PartStructure Ids for which Tags should be auto-generated, in
  * the given repository.
  * 
  * @param object Id $repositoryId
  * @return object IdIterator
  * @access public
  * @since 11/21/06
  */
 function getPartStructureIdsForTagGeneration($repositoryId)
 {
     if (!isset($this->_cache[$repositoryId->getIdString()])) {
         $this->_cache[$repositoryId->getIdString()] = array();
         $query = new SelectQuery();
         $query->addColumn('fk_partstruct');
         $query->addTable('tag_part_map');
         $query->addWhere("fk_repository ='" . addslashes($repositoryId->getIdString()) . "'");
         $dbc = Services::getService("DatabaseManager");
         $result = $dbc->query($query, $this->getDatabaseIndex());
         // Add tag objects to an array, still sorted by frequency of usage
         $idManager = Services::getService('Id');
         while ($result->hasNext()) {
             $row = $result->next();
             $this->_cache[$repositoryId->getIdString()][] = $idManager->getId($row['fk_partstruct']);
         }
     }
     $iterator = new HarmoniIterator($this->_cache[$repositoryId->getIdString()]);
     return $iterator;
 }
开发者ID:adamfranco,项目名称:harmoni,代码行数:29,代码来源:StructuredMetaDataTagGenerator.class.php


示例20: toSql

function toSql(SelectQuery $obj)
{
    $_string = $obj->__toString();
    $_conditions = $obj->conditions();
    $_tables = $obj->getTables();
    $_fields = $obj->getFields();
    foreach ($_tables as $k => $t) {
        if (!empty($t['alias'])) {
            $_string = str_replace('{' . $t['table'] . '}', $t['table'] . ' as', $_string);
        } else {
            $_string = str_replace('{' . $t['table'] . '}', $t['table'], $_string);
        }
    }
    foreach ($_conditions as $k => $c) {
        if (is_int($c['value'])) {
            $_string = str_replace(':db_condition_placeholder_' . $k, $c['value'], $_string);
        } else {
            $_string = str_replace(':db_condition_placeholder_' . $k, "'" . $c['value'] . "'", $_string);
        }
    }
    return $_string;
}
开发者ID:edwinraycom,项目名称:vals-soc,代码行数:22,代码来源:helper_functions.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP Self类代码示例发布时间:2022-05-23
下一篇:
PHP Select类代码示例发布时间: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