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


PHP Zend_Db_Adapter_Pdo_Mysql::query方法代码示例

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


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

示例1: query

 /**
  * Prepares and executes an SQL statement with bound data.
  *
  * @param  mixed  $sql  The SQL statement with placeholders.
  *                      May be a string or Zend_Db_Select.
  * @param  mixed  $bind An array of data to bind to the placeholders.
  * @return Zend_Db_Statement_Interface
  */
 public function query($sql, $bind = array())
 {
     $attempts = 0;
     while ($attempts < self::ATTEMPTS) {
         try {
             return parent::query($sql, $bind);
         } catch (Zend_Db_Exception $ex) {
             $this->catchDbException($ex);
             $attempts++;
         }
     }
     throw new Exception('Query could not be executed in ' . self::ATTEMPTS . ' attempts. Each waiting for ' . self::SLEEP_BETWEEN_ATTEMPTS . ' seconds. ' . 'See the previous exception: "' . $ex->getMessage() . '"', 0, $ex);
 }
开发者ID:olhsha,项目名称:OpenSKOS2tempMeertens,代码行数:21,代码来源:Reconnecting.php

示例2: query

 /**
  * Special handling for PDO query().
  * All bind parameter names must begin with ':'
  *
  * @param string|Zend_Db_Select $sql The SQL statement with placeholders.
  * @param array $bind An array of data to bind to the placeholders.
  * @return Zend_Db_Statement_Pdo
  * @throws Zend_Db_Adapter_Exception To re-throw PDOException.
  */
 public function query($sql, $bind = array())
 {
     if (empty($bind) && $sql instanceof Zend_Db_Select) {
         $bind = $sql->getBind();
     }
     if (!empty($bind)) {
         foreach ($bind as $name => $value) {
             if ($value instanceof Zend_Date) {
                 $bind[$name] = $value->toString('yyyy-MM-dd HH:mm:ss');
             }
         }
     }
     return parent::query($sql, $bind);
 }
开发者ID:nvdnkpr,项目名称:Enlight,代码行数:23,代码来源:Mysql.php

示例3: getNoteTypes

 /**
  * get all note types
  *
  * @param boolean|optional $onlyNonSystemNotes
  * @return Tinebase_Record_RecordSet of Tinebase_Model_NoteType
  */
 public function getNoteTypes($onlyNonSystemNotes = false, $onlyIds = false)
 {
     $select = $this->_db->select()->from(array('note_types' => SQL_TABLE_PREFIX . 'note_types'), $onlyIds ? 'id' : '*');
     if ($onlyNonSystemNotes) {
         $select->where($this->_db->quoteIdentifier('is_user_type') . ' = 1');
     }
     $stmt = $this->_db->query($select);
     if ($onlyIds) {
         $types = $stmt->fetchAll(Zend_Db::FETCH_COLUMN);
     } else {
         $rows = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
         $types = new Tinebase_Record_RecordSet('Tinebase_Model_NoteType', $rows, true);
     }
     return $types;
 }
开发者ID:bitExpert,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:21,代码来源:Notes.php

示例4: query

 /**
  * Special handling for PDO query().
  * All bind parameter names must begin with ':'.
  *
  * @param string|Zend_Db_Select $sql  The SQL statement with placeholders.
  * @param mixed                 $bind An array of data or data itself to bind to the placeholders.
  *
  * @return Zend_Db_Statement_Pdo
  * @throws Zend_Db_Adapter_Exception To re-throw PDOException.
  */
 public function query($sql, $bind = [])
 {
     $this->_debugTimer();
     $result = null;
     try {
         $this->_checkDdlTransaction($sql);
         $this->_prepareQuery($sql, $bind);
         $maxTries = 1 + (isset($this->_config['retries']) ? min(max(intval($this->_config['retries']), 0), 5) : 5);
         $retryPower = isset($this->_config['retry_power']) ? min(max(intval($this->_config['retry_power']), 1), 5) : 2;
         $try = 0;
         while ($try < $maxTries) {
             try {
                 $result = Zend_Db_Adapter_Pdo_Mysql::query($sql, $bind);
                 $try = $maxTries;
             } catch (Exception $e) {
                 $try++;
                 Mage::log("Max retry:{$maxTries} retry power:{$retryPower}", Zend_Log::DEBUG);
                 if ($try < $maxTries) {
                     $message = null;
                     if ($e instanceof PDOException) {
                         $message = $e->getMessage();
                     } elseif ($e->getPrevious() instanceof PDOException) {
                         $message = $e->getPrevious()->getMessage();
                     } else {
                         Mage::log("Exception is instance of " . get_class($e), Zend_Log::DEBUG);
                         Mage::log("Previous Exception is instance of " . get_class($e->getPrevious()), Zend_Log::DEBUG);
                     }
                     if ($message && in_array($message, $this->retryOnMessages)) {
                         $sleepSeconds = pow($try, $retryPower);
                         Mage::log("Retrying query [retry:{$try} delay:{$sleepSeconds}]: {$message}", Zend_Log::DEBUG);
                         if ($try === 1) {
                             Mage::logException($e);
                         }
                         sleep($sleepSeconds);
                         continue;
                     }
                 }
                 throw $e;
             }
         }
     } catch (Exception $e) {
         $this->_debugStat(self::DEBUG_QUERY, $sql, $bind);
         $this->_debugException($e);
     }
     $this->_debugStat(self::DEBUG_QUERY, $sql, $bind, $result);
     return $result;
 }
开发者ID:dburlage-pantek,项目名称:Aoe_DbRetry,代码行数:57,代码来源:Adapter.php

示例5: getAllAsociado

 /**
  * SUPER-FIXME!
  */
 public static function getAllAsociado($sitio = null, $pagina = null, $limit = 0, $orden = "id")
 {
     $registry = Zend_Registry::getInstance();
     $r = $registry->get('config');
     $db = new Zend_Db_Adapter_Pdo_Mysql(array('host' => $r->db->config->host, 'username' => $r->db->config->username, 'password' => $r->db->config->password, 'dbname' => $r->db->config->dbname));
     $sql = ' select distinct(a.id),a.*, pa.* from archivos as a left join paginas_archivos as pa ON pa.id_archivo = a.id ';
     if ($sitio) {
         $where = "where ";
         $sql_add[] = "a.id_sitio = " . $sitio . " ";
     }
     if ($pagina) {
         $where = "where ";
         $sql_add[] = "pa.id_pagina = " . $pagina . " ";
     }
     $where = $where . implode(' AND ', $sql_add);
     echo $sql . $where;
     $result = $db->query($sql . $where);
     $archivos = $result->fetchAll();
     return $archivos;
 }
开发者ID:anavarretev,项目名称:surforce-cms,代码行数:23,代码来源:Archivos.php

示例6: getApplicationRights

 /**
  * returns rights for given application and accountId
  *
  * @param   string $_application the name of the application
  * @param   int $_accountId the numeric account id
  * @return  array list of rights
  * @throws  Tinebase_Exception_AccessDenied
  * 
  * @todo    add right group by to statement if possible or remove duplicates in result array
  */
 public function getApplicationRights($_application, $_accountId)
 {
     $application = Tinebase_Application::getInstance()->getApplicationByName($_application);
     if ($application->status != 'enabled') {
         throw new Tinebase_Exception_AccessDenied('User has no rights. the application is disabled.');
     }
     $roleMemberships = $this->getRoleMemberships($_accountId);
     $select = $this->_db->select()->from(SQL_TABLE_PREFIX . 'role_rights', array('account_rights' => Tinebase_Backend_Sql_Command::getAggregateFunction($this->_db, $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . 'role_rights.right'))))->where($this->_db->quoteInto($this->_db->quoteIdentifier(SQL_TABLE_PREFIX . 'role_rights.application_id') . ' = ?', $application->getId()))->where($this->_db->quoteInto($this->_db->quoteIdentifier('role_id') . ' IN (?)', $roleMemberships))->group(SQL_TABLE_PREFIX . 'role_rights.application_id');
     $stmt = $this->_db->query($select);
     $row = $stmt->fetch(Zend_Db::FETCH_ASSOC);
     if ($row === false) {
         return array();
     }
     $rights = explode(',', $row['account_rights']);
     // remove duplicates
     $result = array();
     foreach ($rights as $right) {
         if (!in_array($right, $result)) {
             $result[] = $right;
         }
     }
     return $result;
 }
开发者ID:rodrigofns,项目名称:ExpressoLivre3,代码行数:33,代码来源:Roles.php

示例7: testDb

 /**
  * Operational test for the MySQL database instance:
  * @param  PDO|Zend_Db_Adapter_Pdo_Mysql  $db  Zend Db adapter instance
  * @return boolean   sanity check result
  */
 private static function testDb($db)
 {
     $expected = array('posts' => null, 'users' => null, 'topics' => null, 'attachments' => null);
     foreach ($db->query('show tables') as $row) {
         unset($expected[array_pop($row)]);
     }
     if (count($expected)) {
         ZFDemo_Log::log(_('database missing tables: ') . implode(' ', $expected));
         return false;
     }
     return true;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:17,代码来源:bootstrap.php

示例8: query

 /**
  * Special handling for PDO query().
  * All bind parameter names must begin with ':'
  *
  * @param string|Zend_Db_Select $sql The SQL statement with placeholders.
  * @param array $bind An array of data to bind to the placeholders.
  * @return Zend_Db_Pdo_Statement
  * @throws Zend_Db_Adapter_Exception To re-throw PDOException.
  */
 public function query($sql, $bind = array())
 {
     $this->_debugTimer();
     try {
         $sql = (string) $sql;
         if (strpos($sql, ':') !== false || strpos($sql, '?') !== false) {
             $this->_bindParams = $bind;
             $sql = preg_replace_callback('#(([\'"])((\\2)|((.*?[^\\\\])\\2)))#', array($this, 'proccessBindCallback'), $sql);
             Varien_Exception::processPcreError();
             $bind = $this->_bindParams;
         }
         $result = parent::query($sql, $bind);
     } catch (Exception $e) {
         $this->_debugStat(self::DEBUG_QUERY, $sql, $bind);
         $this->_debugException($e);
     }
     $this->_debugStat(self::DEBUG_QUERY, $sql, $bind, $result);
     return $result;
 }
开发者ID:votanlean,项目名称:Magento-Pruebas,代码行数:28,代码来源:Mysql.php

示例9: _query

    /**
     * Special handling for PDO query().
     * All bind parameter names must begin with ':'.
     *
     * @param string|\Zend_Db_Select $sql The SQL statement with placeholders.
     * @param mixed $bind An array of data or data itself to bind to the placeholders.
     * @return \Zend_Db_Statement_Pdo|void
     * @throws \Zend_Db_Adapter_Exception To re-throw \PDOException.
     * @throws LocalizedException In case multiple queries are attempted at once, to protect from SQL injection
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     */
    protected function _query($sql, $bind = [])
    {
        $connectionErrors = [
            2006, // SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
            2013,  // SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query
        ];
        $triesCount = 0;
        do {
            $retry = false;
            $this->logger->startTimer();
            try {
                $this->_checkDdlTransaction($sql);
                $this->_prepareQuery($sql, $bind);
                $result = parent::query($sql, $bind);
                $this->logger->logStats(LoggerInterface::TYPE_QUERY, $sql, $bind, $result);
                return $result;
            } catch (\Exception $e) {
                // Finalize broken query
                $profiler = $this->getProfiler();
                if ($profiler instanceof Profiler) {
                    /** @var Profiler $profiler */
                    $profiler->queryEndLast();
                }

                /** @var $pdoException \PDOException */
                $pdoException = null;
                if ($e instanceof \PDOException) {
                    $pdoException = $e;
                } elseif (($e instanceof \Zend_Db_Statement_Exception) && ($e->getPrevious() instanceof \PDOException)) {
                    $pdoException = $e->getPrevious();
                }

                // Check to reconnect
                if ($pdoException && $triesCount < self::MAX_CONNECTION_RETRIES
                    && in_array($pdoException->errorInfo[1], $connectionErrors)
                ) {
                    $retry = true;
                    $triesCount++;
                    $this->closeConnection();
                    $this->_connect();
                }

                if (!$retry) {
                    $this->logger->logStats(LoggerInterface::TYPE_QUERY, $sql, $bind);
                    $this->logger->critical($e);
                    throw $e;
                }
            }
        } while ($retry);
    }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:61,代码来源:Mysql.php

示例10: connectDB

 private function connectDB()
 {
     $xml = readLangFile('config/config.xml');
     setIncludePath(array('special' => array('folder' => $xml->host->folder)));
     try {
         $dbconfig = array('host' => $xml->database->host, 'username' => $xml->database->username, 'password' => $xml->database->password, 'dbname' => $xml->database->db);
         //here we check for database type
         switch ($xml->database->type) {
             case "mysql":
                 require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
                 $db = new Zend_Db_Adapter_Pdo_Mysql($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 $smt = $db->query("SET NAMES 'utf8'");
                 $smt->execute();
                 break;
             default:
                 require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
                 $db = new Zend_Db_Adapter_Pdo_Mysql($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 $smt = $db->query("SET NAMES 'utf8'");
                 $smt->execute();
         }
     } catch (Zend_Db_Adapter_Exception $e) {
         $this->triggerError($this->language['db_connect_error']);
     } catch (Zend_Exception $e) {
         $this->triggerError($this->language['db_factory_error']);
     }
     $this->db = $db;
 }
开发者ID:basdog22,项目名称:Qool,代码行数:31,代码来源:install.php

示例11: query

 function query($sql, $bind = array())
 {
     My_Logger::log('QUERY: ' . $sql);
     return parent::query($sql, $bind);
 }
开发者ID:sutantyo,项目名称:itec810,代码行数:5,代码来源:Bootstrap.php

示例12: query

 /**
  * Special handling for PDO query().
  * All bind parameter names must begin with ':'.
  *
  * @param string|Zend_Db_Select $sql The SQL statement with placeholders.
  * @param mixed $bind An array of data or data itself to bind to the placeholders.
  * @return Zend_Db_Pdo_Statement
  * @throws Zend_Db_Adapter_Exception To re-throw PDOException.
  */
 public function query($sql, $bind = array())
 {
     $this->_debugTimer();
     try {
         //commenting below function as it doesnot alow user to perform trucate or create using begin and commit functionalities - Issue in Magento Enterprise 1.12
         //$this->_checkDdlTransaction($sql);
         $this->_prepareQuery($sql, $bind);
         $result = parent::query($sql, $bind);
     } catch (Exception $e) {
         $this->_debugStat(self::DEBUG_QUERY, $sql, $bind);
         $this->_debugException($e);
     }
     $this->_debugStat(self::DEBUG_QUERY, $sql, $bind, $result);
     return $result;
 }
开发者ID:sagmahajan,项目名称:aswan_release,代码行数:24,代码来源:Mysql.php

示例13: query

 /**
  * Special handling for PDO query().
  * All bind parameter names must begin with ':'.
  *
  * @param string|\Zend_Db_Select $sql The SQL statement with placeholders.
  * @param mixed $bind An array of data or data itself to bind to the placeholders.
  * @return \Zend_Db_Statement_Pdo|void
  * @throws \Zend_Db_Adapter_Exception To re-throw \PDOException.
  */
 public function query($sql, $bind = array())
 {
     $connectionErrors = array(2006, 2013);
     $triesCount = 0;
     do {
         $retry = false;
         $this->_debugTimer();
         try {
             $this->_checkDdlTransaction($sql);
             $this->_prepareQuery($sql, $bind);
             $result = parent::query($sql, $bind);
             $this->_debugStat(self::DEBUG_QUERY, $sql, $bind, $result);
             return $result;
         } catch (\Exception $e) {
             // Finalize broken query
             $profiler = $this->getProfiler();
             if ($profiler instanceof Profiler) {
                 /** @var Profiler $profiler */
                 $profiler->queryEndLast();
             }
             /** @var $pdoException \PDOException */
             $pdoException = null;
             if ($e instanceof \PDOException) {
                 $pdoException = $e;
             } elseif ($e instanceof \Zend_Db_Statement_Exception && $e->getPrevious() instanceof \PDOException) {
                 $pdoException = $e->getPrevious();
             }
             // Check to reconnect
             if ($pdoException && $triesCount < self::MAX_CONNECTION_RETRIES && in_array($pdoException->errorInfo[1], $connectionErrors)) {
                 $retry = true;
                 $triesCount++;
                 $this->closeConnection();
                 $this->_connect();
             }
             if (!$retry) {
                 $this->_debugStat(self::DEBUG_QUERY, $sql, $bind);
                 $this->_debugException($e);
             }
         }
     } while ($retry);
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:50,代码来源:Mysql.php

示例14: query

 /**
  * Prepares and executes an SQL statement with bound data.
  * Caches prepared statements to avoid preparing the same query more than once
  *
  * @param string|Zend_Db_Select  $sql   The SQL statement with placeholders.
  * @param array                  $bind  An array of data to bind to the placeholders.
  * @return Zend_Db_Statement_Interface
  */
 public function query($sql, $bind = array())
 {
     if (!is_string($sql)) {
         return parent::query($sql, $bind);
     }
     if (isset($this->cachePreparedStatement[$sql])) {
         if (!is_array($bind)) {
             $bind = array($bind);
         }
         $stmt = $this->cachePreparedStatement[$sql];
         $stmt->execute($bind);
         return $stmt;
     }
     $stmt = parent::query($sql, $bind);
     $this->cachePreparedStatement[$sql] = $stmt;
     return $stmt;
 }
开发者ID:nomoto-ubicast,项目名称:piwik,代码行数:25,代码来源:Mysql.php

示例15: connectDB

 private function connectDB()
 {
     try {
         $dbconfig = array('host' => $this->config->database->host, 'username' => $this->config->database->username, 'password' => $this->config->database->password, 'dbname' => $this->config->database->db);
         $dbconfig = $this->doQoolHook('front_pre_connectdb', $dbconfig);
         //here we check for database type
         switch ($this->config->database->type) {
             case "mysql":
                 $db = new Zend_Db_Adapter_Pdo_Mysql($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 $smt = $db->query("SET NAMES 'utf8'");
                 $smt->execute();
                 break;
             case "sqlite":
                 $db = new Zend_Db_Adapter_Pdo_Sqlite($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 break;
             default:
                 $db = new Zend_Db_Adapter_Pdo_Mysql($dbconfig);
                 $db->getConnection();
                 $db->setFetchMode(Zend_Db::FETCH_ASSOC);
                 $smt = $db->query("SET NAMES 'utf8'");
                 $smt->execute();
         }
     } catch (Zend_Db_Adapter_Exception $e) {
         $this->triggerError($this->language['db_connect_error']);
     } catch (Zend_Exception $e) {
         $this->triggerError($this->language['db_factory_error']);
     }
     $db = $this->doQoolHook('front_after_connectdb', $db);
     $this->db = $db;
 }
开发者ID:basdog22,项目名称:Qool,代码行数:34,代码来源:Action.php


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