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


PHP CRM_Core_Error::debug_query方法代码示例

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


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

示例1: sourceSQLFile

 /**
  * @param $dsn
  * @param string $fileName
  * @param null $prefix
  * @param bool $isQueryString
  * @param bool $dieOnErrors
  */
 public static function sourceSQLFile($dsn, $fileName, $prefix = NULL, $isQueryString = FALSE, $dieOnErrors = TRUE)
 {
     require_once 'DB.php';
     $db = DB::connect($dsn);
     if (PEAR::isError($db)) {
         die("Cannot open {$dsn}: " . $db->getMessage());
     }
     if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) {
         $db->query('SET SESSION sql_mode = STRICT_TRANS_TABLES');
     }
     if (!$isQueryString) {
         $string = $prefix . file_get_contents($fileName);
     } else {
         // use filename as query string
         $string = $prefix . $fileName;
     }
     // get rid of comments starting with # and --
     $string = preg_replace("/^#[^\n]*\$/m", "\n", $string);
     $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
     $queries = preg_split('/;\\s*$/m', $string);
     foreach ($queries as $query) {
         $query = trim($query);
         if (!empty($query)) {
             CRM_Core_Error::debug_query($query);
             $res =& $db->query($query);
             if (PEAR::isError($res)) {
                 if ($dieOnErrors) {
                     die("Cannot execute {$query}: " . $res->getMessage());
                 } else {
                     echo "Cannot execute {$query}: " . $res->getMessage() . "<p>";
                 }
             }
         }
     }
 }
开发者ID:routinet,项目名称:civicrm-core,代码行数:42,代码来源:File.php

示例2: _query

 /**
  * sends query to database - this is the private one that must work
  *   - internal functions use this rather than $this->query()
  *
  * @param  string  $string
  * @access private
  * @return mixed none or PEAR_Error
  */
 function _query($string)
 {
     global $_DB_DATAOBJECT, $queries, $user;
     $this->_connect();
     CRM_Core_Error::debug_query($string);
     $DB =& $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5];
     $options =& $_DB_DATAOBJECT['CONFIG'];
     $_DB_driver = empty($_DB_DATAOBJECT['CONFIG']['db_driver']) ? 'DB' : $_DB_DATAOBJECT['CONFIG']['db_driver'];
     if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
         $this->debug($string, $log = "QUERY");
     }
     if (strtoupper($string) == 'BEGIN') {
         if ($_DB_driver == 'DB') {
             $DB->autoCommit(false);
         } else {
             $DB->beginTransaction();
         }
         // db backend adds begin anyway from now on..
         return true;
     }
     if (strtoupper($string) == 'COMMIT') {
         $res = $DB->commit();
         if ($_DB_driver == 'DB') {
             $DB->autoCommit(true);
         }
         return $res;
     }
     if (strtoupper($string) == 'ROLLBACK') {
         $DB->rollback();
         if ($_DB_driver == 'DB') {
             $DB->autoCommit(true);
         }
         return true;
     }
     if (!empty($options['debug_ignore_updates']) && strtolower(substr(trim($string), 0, 6)) != 'select' && strtolower(substr(trim($string), 0, 4)) != 'show' && strtolower(substr(trim($string), 0, 8)) != 'describe') {
         $this->debug('Disabling Update as you are in debug mode');
         return $this->raiseError("Disabling Update as you are in debug mode", null);
     }
     //if (@$_DB_DATAOBJECT['CONFIG']['debug'] > 1) {
     // this will only work when PEAR:DB supports it.
     //$this->debug($DB->getAll('explain ' .$string,DB_DATAOBJECT_FETCHMODE_ASSOC), $log="sql",2);
     //}
     // some sim
     $t = explode(' ', microtime());
     $_DB_DATAOBJECT['QUERYENDTIME'] = $time = $t[0] + $t[1];
     for ($tries = 0; $tries < 3; $tries++) {
         if ($_DB_driver == 'DB') {
             $result = $DB->query($string);
         } else {
             switch (strtolower(substr(trim($string), 0, 6))) {
                 case 'insert':
                 case 'update':
                 case 'delete':
                     $result = $DB->exec($string);
                     break;
                 default:
                     $result = $DB->query($string);
                     break;
             }
         }
         // see if we got a failure.. - try again a few times..
         if (!is_a($result, 'PEAR_Error')) {
             break;
         }
         if ($result->getCode() != -14) {
             // *DB_ERROR_NODBSELECTED
             break;
             // not a connection error..
         }
         sleep(1);
         // wait before retyring..
         $DB->connect($DB->dsn);
     }
     if (is_a($result, 'PEAR_Error')) {
         if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
             $this->debug($result->toString(), "Query Error", 1);
         }
         return $this->raiseError($result);
     }
     /* CRM-3225 */
     if (function_exists('variable_get') && variable_get('dev_query', 0)) {
         // this is for drupal devel module
         // If devel.module query logging is enabled, prepend a comment with the username and calling function
         // to the SQL string.
         $bt = debug_backtrace();
         // t() may not be available yet so we don't wrap 'Anonymous'
         $name = $user->uid ? $user->name : variable_get('anonymous', 'Anonymous');
         $query = $bt[3]['function'] . "\n/* " . $name . ' */ ' . str_replace("\n ", '', $string);
         list($usec, $sec) = explode(' ', microtime());
         $stop = (double) $usec + (double) $sec;
         $diff = $stop - $time;
         $queries[] = array($query, $diff);
//.........这里部分代码省略.........
开发者ID:TheCraftyCanvas,项目名称:aegir-platforms,代码行数:101,代码来源:DataObject.php


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