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


PHP DataSource::query方法代码示例

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


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

示例1: MySQLCursor

 /**
  * Query the data source.
  * <p>This class makes no assumption about the content of the query
  * object, but the behavior of the resulting Cursor object should be
  * consistent between data source implementations.
  * @param mixed $query Some sort of query that will be understood by
  * the implemented data source.
  * @return Cursor The result of the query, FALSE otherwise (though this
  * is unlikely to occur because of the fatal error event when a query
  * fails).
  */
 function &query($query)
 {
     if (!($rv =& parent::query($query))) {
         $result = mysql_query($query, $this->myLink);
         if ($result) {
             $rv = new MySQLCursor($result, $this);
         } else {
             LogError("MySQL query failed: \n" . $query . "\n" . mysql_error());
             LogFatal("MySQL query failed");
             $rv = FALSE;
         }
     }
     return $rv;
 }
开发者ID:bd808,项目名称:casadebender,代码行数:25,代码来源:MySQLDataSource.php

示例2: querySql

 public static function querySql($sql, $params, $form = '', $dsname = '')
 {
     $ds = new DataSource();
     if ($form != '') {
         $fb = FormBuilder::load($form);
         $ds->builder = $fb;
         if ($dsname != '') {
             $field = $fb->findField(['name' => $dsname]);
             $ds->params = $field['params'];
         }
     }
     $ds->sql = $sql;
     return $ds->query($params);
 }
开发者ID:alfhan,项目名称:plansys,代码行数:14,代码来源:DataSource.php

示例3: array

 /**
  * Query the user input.  Recognizes this minimal SQL statement form:
  *
  * select key1,key2,key3,etc
  * from assoc_array
  * where id_key = value
  *
  * TODO: Currently does not recognize update, insert, or delete queries
  * though a short leap of logic could imagine that update and insert
  * queries might thunk HTML output for displaying/editing a persistent
  * object.  I'm not sure that logic can leap so far as to delete a an
  * object from the user.
  *
  * @param string $query An SQL select statment of the format noted
  * above.
  * @return Cursor The result of the query, FALSE otherwise (though this
  * is unlikely to occur because of the fatal error event when a query
  * fails).
  */
 function &query($query)
 {
     if (!($rv =& parent::query($query))) {
         $parts = array();
         if (eregi("select(.*)from(.*)where(.*)", $query, $parts)) {
             $fields = array();
             $table = trim($parts[2]);
             $where = trim($parts[3]);
             $wparts = array();
             if (eregi("(.*)=(.*)", $where, $wparts)) {
                 #LogDebug( $wparts );
                 $idfield = ExtractFieldAlias($table, $wparts[1]);
                 $idmatch = trim($wparts[2]);
                 $tmp = array();
                 if (ereg("^\\'(.*)\\'\$", $idmatch, $tmp)) {
                     $idmatch = $tmp[1];
                 }
             } elseif (eregi("(.*) is null", $where, $wparts)) {
                 $idfield = ExtractFieldAlias($table, $wparts[1]);
                 $idmatch = NULL;
             } else {
                 LogError("Invalid user input where clause: {$query}");
                 LogFatal("Invalid user input where clause");
             }
             $gotid = FALSE;
             foreach (split(',', $parts[1]) as $field) {
                 $alias = ExtractFieldAlias($table, $field);
                 if ($idfield == $alias) {
                     $gotid = TRUE;
                 }
                 $fields[] = $alias;
             }
         } else {
             LogError("Invalid user input query: {$query}");
             LogFatal("Invalid user input query");
         }
         $rv = array();
         if (array_key_exists($table, $_REQUEST) && is_array($tin = $_REQUEST[$table])) {
             #LogDebug( "--$idfield--" );
             #LogDebug( $tin );
             if (array_key_exists($idfield, $tin)) {
                 if ($rec = ExtractRecordFromRequest($table, $idfield, $idmatch, $fields, $tin)) {
                     $rv[] = $rec;
                 }
             } else {
                 foreach ($tin as $trow) {
                     if ($rec = ExtractRecordFromRequest($table, $idfield, $idmatch, $fields, $trow)) {
                         $rv[] = $rec;
                     }
                 }
             }
         } else {
             if ($rec = ExtractRecordFromRequest($table, $idfield, $idmatch, $fields, $_REQUEST)) {
                 $rv[] = $rec;
             }
         }
     }
     $r = new ArrayCursor(&$rv, &$this);
     #LogDebug($r);
     return $r;
 }
开发者ID:bd808,项目名称:casadebender,代码行数:80,代码来源:UserInputDataSource.php

示例4: loadOrImport

 /**
  * Implementation of load and import varies only slight, so both
  * methods refer to this helper method.
  * @param bool $do_load TRUE for load, FALSE for import.
  * @param ChunsuObject $loadme The object to load.
  * @param DataSource $source The data source to load the object from.
  * @return bool TRUE is successful, FALSE otherwise.
  */
 function loadOrImport($do_load, &$loadme, $source)
 {
     $pkfield =& $this->config->get('primary-key');
     $pka =& $pkfield->get('alias');
     $core =& $loadme->getCore();
     if (is_array($core) || is_object($core)) {
         $dummy =& $loadme->getDummy();
         $pkval = $dummy->get($pka);
     } else {
         $pkval = $core;
     }
     if (!is_null($pkval)) {
         $gen = new SQLGenerator($loadme->getCore());
         $cursor = $source->query($gen->select($this->config));
         if ($cursor->getNext()) {
             $rec =& $cursor->get();
             if ($do_load) {
                 $loadme->setref($rec);
                 $loadme->is_new = FALSE;
             } else {
                 $loadme->bulkSet($rec);
             }
             return TRUE;
             // TODO: keep reading and handle conflicts if >1 record
         }
     }
     if (!$loadme->config->get('create-on-save')) {
         LogError("Cannot load object: no records found.\n" . $loadme->trace());
         LogFatal("Cannot load object: no records found. ");
     }
     return TRUE;
 }
开发者ID:bd808,项目名称:casadebender,代码行数:40,代码来源:SQLStorageMethod.php

示例5: _serializeOption

 /**
  * Serialize a certain option key-value pair (meaning it has been updated)
  */
 public function _serializeOption($optionKey, $optionValue)
 {
     // First sanitize $optionValue
     if ($this->_realmConfig[$optionKey]["type"] == "int") {
         if (!is_numeric($optionValue)) {
             throw "Bad option data. " . $this->_optionRealm . ".{$optionKey} expects numeric value, {$optionValue} given!";
         }
     } else {
         if ($this->_realmConfig[$optionKey]["type"] == "boolean") {
             $optionValue = $optionValue ? '1' : '0';
         } else {
             $optionValue = "'" . DataSource::escape($optionValue) . "'";
         }
     }
     if (!defined("OPTIONS_SUPPRESS_DELETE")) {
         DataSource::query("delete from " . $this->_optionRealm . "_options where id=" . $this->_internalID . " and " . "optionname='" . $optionKey . "'");
     }
     DataSource::query("insert into " . $this->_optionRealm . "_options values (" . $this->_internalID . "," . "'{$optionKey}',{$optionValue})");
 }
开发者ID:almaopen,项目名称:SwissMVC,代码行数:22,代码来源:options.php

示例6: delete

 public static function delete($name, $array)
 {
     $sql = "delete FROM " . $name;
     if ($array) {
         $first = true;
         $sql .= " where ";
         foreach ($array as $key => $value) {
             if (!$first) {
                 $sql = " and ";
             } else {
                 $first = false;
             }
             $sql .= $key . "='" . $value . "' ";
         }
     }
     LOG::trace("sql:{$sql}");
     $ds = new DataSource();
     $result = $ds->query($sql);
     if (!is_numeric($result)) {
         if ($ds->error()) {
             throw new Exception($ds->error());
         }
     }
     return $result;
 }
开发者ID:r67,项目名称:masomatic,代码行数:25,代码来源:mom.php


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