當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Sql::getAdapter方法代碼示例

本文整理匯總了PHP中Zend\Db\Sql\Sql::getAdapter方法的典型用法代碼示例。如果您正苦於以下問題:PHP Sql::getAdapter方法的具體用法?PHP Sql::getAdapter怎麽用?PHP Sql::getAdapter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Db\Sql\Sql的用法示例。


在下文中一共展示了Sql::getAdapter方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: executeStatement

 /**
  * Execute a statement
  *
  * @todo move to driver if not will only support MySQL
  *
  * @throws Exception\ForeignKeyException when insertion failed because of an invalid foreign key
  * @throws Exception\DuplicateEntryException when insertion failed because of an invalid foreign key
  * @throws Exception\NotNullException when insertion failed because a column cannot be null
  * @throws Exception\RuntimeException when insertion failed for another reason
  *
  * @param string|PreparableSqlInterface $sqlObject
  * @return \Zend\Db\Adapter\Driver\ResultInterface
  */
 protected function executeStatement($sqlObject)
 {
     if ($sqlObject instanceof PreparableSqlInterface) {
         $statement = $this->sql->prepareStatementForSqlObject($sqlObject);
     } elseif (is_string($sqlObject)) {
         $statement = $this->tableManager->getDbAdapter()->createStatement($sqlObject);
     } else {
         //@codeCoverageIgnoreStart
         throw new Exception\InvalidArgumentException(__METHOD__ . ': expects sqlObject to be string or PreparableInterface');
         //@codeCoverageIgnoreEnd
     }
     try {
         $result = $statement->execute();
     } catch (\Exception $e) {
         // In ZF2, PDO_Mysql and MySQLi return different exception,
         // attempt to normalize by catching one exception instead
         // of RuntimeException and InvalidQueryException
         $messages = array();
         $ex = $e;
         do {
             $messages[] = $ex->getMessage();
         } while ($ex = $ex->getPrevious());
         $message = join(', ', array_unique($messages));
         $lmsg = __METHOD__ . ':' . strtolower($message) . '(code:' . $e->getCode() . ')';
         if (strpos($lmsg, 'cannot be null') !== false) {
             // Integrity constraint violation: 1048 Column 'non_null_column' cannot be null
             $rex = new Exception\NotNullException(__METHOD__ . ': ' . $message, $e->getCode(), $e);
             throw $rex;
         } elseif (strpos($lmsg, 'duplicate entry') !== false) {
             $rex = new Exception\DuplicateEntryException(__METHOD__ . ': ' . $message, $e->getCode(), $e);
             throw $rex;
         } elseif (strpos($lmsg, 'constraint violation') !== false || strpos($lmsg, 'foreign key') !== false) {
             $rex = new Exception\ForeignKeyException(__METHOD__ . ': ' . $message, $e->getCode(), $e);
             throw $rex;
         } else {
             if ($sqlObject instanceof SqlInterface) {
                 $sql_string = $sqlObject->getSqlString($this->sql->getAdapter()->getPlatform());
             } else {
                 $sql_string = $sqlObject;
             }
             $iqex = new Exception\RuntimeException(__METHOD__ . ': ' . $message . "[{$sql_string}]", $e->getCode(), $e);
             throw $iqex;
         }
     }
     return $result;
 }
開發者ID:robocoder,項目名稱:solublecomponents,代碼行數:59,代碼來源:Table.php

示例2: adapter

 protected function adapter()
 {
     return $this->sql->getAdapter();
 }
開發者ID:railsphp,項目名稱:framework,代碼行數:4,代碼來源:SqlRelation.php


注:本文中的Zend\Db\Sql\Sql::getAdapter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。