当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPWS_DB::prefixQuery方法代码示例

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


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

示例1: select

 /**
  * Retrieves information from the database.
  * Select utilizes parameters set previously in the object
  * (i.e. addWhere, addColumn, setLimit, etc.)
  * You may also set the "type" of result: assoc (associative)
  * col (columns), min (minimum result), max (maximum result), one (a single column from a
  * single row), row (a single row), count (a tally of rows) or all, the default.
  * All returns an associate array containing the requested information.
  *
  */
 public function select($type = null, $sql = null)
 {
     if (empty($sql)) {
         if (!empty($this->sql)) {
             $sql =& $this->sql;
         }
     }
     PHPWS_DB::touchDB();
     if (isset($type) && is_string($type)) {
         $type = strtolower($type);
     }
     $mode = $this->getMode();
     $indexby = $this->getIndexBy();
     if (!isset($sql)) {
         $sql = $this->getTheQuery($type);
     } else {
         $mode = MDB2_FETCHMODE_ASSOC;
     }
     $sql = PHPWS_DB::prefixQuery($sql);
     if ($this->_test_mode) {
         var_dump($sql);
         exit($sql);
     }
     if ($this->return_query) {
         return trim($sql);
     }
     // assoc does odd things if the resultant return is two items or less
     // not sure why it is coded that way. Use the default instead
     switch ($type) {
         case 'assoc':
             PHPWS_DB::logDB($sql);
             return $GLOBALS['PHPWS_DB']['connection']->getAssoc($sql, null, null, $mode);
             break;
         case 'col':
             if (empty($sql) && empty($this->columns)) {
                 return PHPWS_Error::get(PHPWS_DB_NO_COLUMN_SET, 'core', 'PHPWS_DB::select');
             }
             if (isset($indexby)) {
                 PHPWS_DB::logDB($sql);
                 $result = $GLOBALS['PHPWS_DB']['connection']->queryAll($sql, null, $mode);
                 if (PHPWS_Error::isError($result)) {
                     return $result;
                 }
                 return PHPWS_DB::_indexBy($result, $indexby, true);
             }
             PHPWS_DB::logDB($sql);
             return $GLOBALS['PHPWS_DB']['connection']->queryCol($sql);
             break;
         case 'min':
         case 'max':
         case 'one':
             PHPWS_DB::logDB($sql);
             return $GLOBALS['PHPWS_DB']['connection']->queryOne($sql, null, $mode);
             break;
         case 'row':
             PHPWS_DB::logDB($sql);
             return $GLOBALS['PHPWS_DB']['connection']->queryRow($sql, null, $mode);
             break;
         case 'count':
             PHPWS_DB::logDB($sql);
             if (empty($this->columns)) {
                 $result = $GLOBALS['PHPWS_DB']['connection']->queryRow($sql);
                 if (PHPWS_Error::isError($result)) {
                     return $result;
                 }
                 return $result[0];
             } else {
                 $result = $GLOBALS['PHPWS_DB']['connection']->queryCol($sql);
                 if (PHPWS_Error::isError($result)) {
                     return $result;
                 }
                 return count($result);
             }
             break;
         case 'count_array':
             PHPWS_DB::logDB($sql);
             $result = $GLOBALS['PHPWS_DB']['connection']->queryAll($sql, null, $mode);
             if (PHPWS_Error::isError($result)) {
                 return $result;
             }
             return $result;
             break;
         case 'all':
         default:
             PHPWS_DB::logDB($sql);
             $result = $GLOBALS['PHPWS_DB']['connection']->queryAll($sql, null, $mode);
             if (PHPWS_Error::isError($result)) {
                 return $result;
             }
             if (isset($indexby)) {
//.........这里部分代码省略.........
开发者ID:jeffrafter,项目名称:InternshipInventory,代码行数:101,代码来源:SubselectDatabase.php

示例2: select

 /**
  * Retrieves information from the database.
  * Select utilizes parameters set previously in the object
  * (i.e. addWhere, addColumn, setLimit, etc.)
  * You may also set the "type" of result: assoc (associative)
  * col (columns), min (minimum result), max (maximum result), one (a single column from a
  * single row), row (a single row), count (a tally of rows) or all, the default.
  * All returns an associate array containing the requested information.
  *
  */
 public function select($type = null, $sql = null)
 {
     if (empty($sql)) {
         if (!empty($this->sql)) {
             $sql =& $this->sql;
         }
     }
     PHPWS_DB::touchDB();
     if (isset($type) && is_string($type)) {
         $type = strtolower($type);
     }
     $mode = $this->getMode();
     $indexby = $this->getIndexBy();
     if (!isset($sql)) {
         $sql_array = $this->getSelectSQL($type);
         if (PHPWS_Error::isError($sql_array)) {
             return $sql_array;
         }
         // extract will get $columns, $table, $where, $group_by
         // $order, and $limit
         extract($sql_array);
         if ($type == 'count' || $type == 'count_array') {
             if (empty($columns)) {
                 // order and group_by are not needed if count is
                 // using all rows
                 $order = null;
                 $group_by = null;
                 $columns = 'COUNT(*)';
             } else {
                 $add_group = $columns;
                 $columns .= ', COUNT(*)';
                 if (empty($group_by)) {
                     $group_by = "GROUP BY {$add_group}";
                 }
             }
         }
         if (!empty($where)) {
             $where = 'WHERE ' . $where;
         }
         if ($this->isDistinct()) {
             $distinct = 'DISTINCT';
         } else {
             $distinct = null;
         }
         $sql = "SELECT {$distinct} {$columns} FROM {$table} {$where} {$group_by} {$order} {$limit}";
     } else {
         $mode = MDB2_FETCHMODE_ASSOC;
     }
     $sql = PHPWS_DB::prefixQuery($sql);
     if ($this->_test_mode) {
         exit($sql);
     }
     if ($this->return_query) {
         return trim($sql);
     }
     switch ($type) {
         case 'assoc':
             /*
              * Note: Previously, Pear's DB class would return two column results
              * as an array with the key as the first column and the value as the
              * second. This behavior was inconsistent with the expected functionality.
              * We had code programmed expecting this behavior. MDB2 did not
              * replicate it, so two column results were broken.
              * The seemingly errant code below brings the result back to the
              * expected action.
              * Users should NOT depend on this code but should instead use the
              * Global\DB class or use this class with setIndexBy and select('col').
              */
             PHPWS_DB::logDB($sql);
             if (count($this->columns) == 2) {
                 $result = $GLOBALS['PHPWS_DB']['connection']->queryAll($sql, null, $mode);
                 if (PHPWS_Error::isError($result)) {
                     return $result;
                 }
                 return PHPWS_DB::_indexBy($result, $this->columns[0]['name'], true);
             }
             return $GLOBALS['PHPWS_DB']['connection']->queryAll($sql, null, $mode);
             break;
         case 'col':
             if (empty($sql) && empty($this->columns)) {
                 return PHPWS_Error::get(PHPWS_DB_NO_COLUMN_SET, 'core', 'PHPWS_DB::select');
             }
             if (isset($indexby)) {
                 PHPWS_DB::logDB($sql);
                 $result = $GLOBALS['PHPWS_DB']['connection']->queryAll($sql, null, $mode);
                 if (PHPWS_Error::isError($result)) {
                     return $result;
                 }
                 return PHPWS_DB::_indexBy($result, $indexby, true);
             }
//.........这里部分代码省略.........
开发者ID:HaldunA,项目名称:phpwebsite,代码行数:101,代码来源:PHPWS_DB.php


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