本文整理匯總了PHP中Zend\Db\Sql\Sql::prepateStatementForSqlObject方法的典型用法代碼示例。如果您正苦於以下問題:PHP Sql::prepateStatementForSqlObject方法的具體用法?PHP Sql::prepateStatementForSqlObject怎麽用?PHP Sql::prepateStatementForSqlObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Db\Sql\Sql
的用法示例。
在下文中一共展示了Sql::prepateStatementForSqlObject方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: save
/**
* @param PostInterface $postObject
*
* @return PostInterface
* @throws \Exception
*/
public function save(PostInterface $postObject)
{
$postData = $this->hydrator->extract($postObject);
unset($postData['id']);
//Neither Insert nor Update needs the ID in the array
if ($postObject->getId()) {
//ID present, it's an update
$action = new Update('post');
$action->set($postData);
$action->where(array('id = ?' => $postObject->getId()));
} else {
// ID not present, it's an Insert
$action = new Insert('post');
$action->values($postData);
}
$sql = new Sql($this->dbAdapter);
$stmt = $sql->prepateStatementForSqlObject($action);
$result = $stmt->execute();
if ($result instanceof ResultInterface) {
if ($newId = $result->getGeneratedValue()) {
//when a value has been generated, set it on the object
$postObject->setId($newId);
}
return $postObject;
}
throw new \Exception("Database error");
}