本文整理汇总了PHP中connection::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP connection::getInstance方法的具体用法?PHP connection::getInstance怎么用?PHP connection::getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection
的用法示例。
在下文中一共展示了connection::getInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter_input
$formdata['password'] = filter_input($input_method, "password", FILTER_SANITIZE_STRING);
//if any of the form fields are empty
if (empty($formdata['username'])) {
$errors['username'] = "Username required";
}
if (empty($formdata['password'])) {
$errors['password'] = "Password required";
}
if (empty($errors)) {
// since none of the form fields were empty,
// store the form data in variables
$username = $formdata['username'];
$password = $formdata['password'];
// create a UserTable object and use it to retrieve
// the users
$connection = connection::getInstance();
$userTable = new UserTable($connection);
$user = $userTable->getUserByUn($username);
// since password fields match, see if the username
// has already been registered - if it is then throw
// and exception
if ($user == null) {
$errors['username'] = "Username is not registered";
} else {
if ($password !== $user->getPassword()) {
$errors['password'] = "Password is incorrect";
}
}
}
if (!empty($errors)) {
throw new Exception("There were errors. Please fix them.");
示例2: getAmount
public function getAmount($type)
{
$b = connection::getInstance()->prepare("SELECT count(*) as count FROM {$type}");
$b->execute();
$resColumn = $b->fetchAll();
if ($resColumn == null) {
return null;
}
return $resColumn[0]["count"];
}