本文整理汇总了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;
}
示例2: adapter
protected function adapter()
{
return $this->sql->getAdapter();
}