当前位置: 首页>>代码示例>>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;未经允许,请勿转载。