本文整理匯總了PHP中UserDao::insert方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserDao::insert方法的具體用法?PHP UserDao::insert怎麽用?PHP UserDao::insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserDao
的用法示例。
在下文中一共展示了UserDao::insert方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addUser
public function addUser($data)
{
return $this->userDao->insert($data);
}
示例2: query
}
private function query($sql)
{
$statement = $this->getDb()->query($sql, PDO::FETCH_ASSOC);
if ($statement === false) {
throw new Exception('fail to create the statement');
}
return $statement;
}
private function execute($sql, User $user)
{
$statement = $this->getDb()->prepare($sql);
$this->executeStatement($statement, $user->toArray());
if (!$user->getUserId()) {
return $this->findById($this->getDb()->lastInsertId());
}
if (!$statement->rowCount()) {
throw new Exception('User with ID "' . $user->getUserId() . '" does not exist');
}
return $user;
}
private function executeStatement(PDOStatement $statement, array $params)
{
if (!$statement->execute($params)) {
throw new Exception('fail to execute the statement');
}
}
}
$userDao = new UserDao();
$userDao->insert(new User());