if (empty($_POST)) {
if (!$this->exporterName) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_import_mapping";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- $row = $statement->fetchArray();
- if ($row['count']) {
+ if ($statement->fetchSingleColumn()) {
$this->showMappingNotice = true;
}
}
$conditionBuilder->add('packageID = ?', array($this->packageID));
}
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_template
".$conditionBuilder;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditionBuilder->getParameters());
- $row = $statement->fetchArray();
- if ($row['count']) {
+
+ if ($statement->fetchSingleColumn()) {
throw new UserInputException('tplName', 'notUnique');
}
}
throw new UserInputException('templateGroupName');
}
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_template_group
WHERE templateGroupName = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->templateGroupName));
- $row = $statement->fetchArray();
- if ($row['count']) {
+
+ if ($statement->fetchSingleColumn()) {
throw new UserInputException('templateGroupName', 'notUnique');
}
}
throw new UserInputException('templateGroupFolderName', 'notValid');
}
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_template_group
WHERE templateGroupFolderName = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->templateGroupFolderName));
- $row = $statement->fetchArray();
- if ($row['count']) {
+
+ if ($statement->fetchSingleColumn()) {
throw new UserInputException('templateGroupFolderName', 'notUnique');
}
}
$conditions->add("userID IN (?)", array($this->userIDs));
// count users
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $count = $statement->fetchArray();
+ $count = $statement->fetchSingleColumn();
// get users
$sql = "SELECT email
echo "<address><![CDATA[".StringUtil::escapeCDATA($row['email'])."]]></address>\n";
}
else {
- echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : '');
+ echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count ? $this->separator : '');
}
$i++;
}
$usersAwaitingApproval = 0;
if (REGISTER_ACTIVATION_METHOD == 2) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user
WHERE activationCode <> 0";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- $row = $statement->fetchArray();
- $usersAwaitingApproval = $row['count'];
+ $usersAwaitingApproval = $statement->fetchSingleColumn();
}
WCF::getTPL()->assign([
// call countItems event
EventHandler::getInstance()->fireAction($this, 'countItems');
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user user_table
".$this->conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($this->conditions->getParameters());
- $row = $statement->fetchArray();
- return $row['count'];
+
+ return $statement->fetchColumn();
}
/**
* @return integer
*/
public function countObjects() {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM ".$this->getDatabaseTableName()." ".$this->getDatabaseTableAlias()."
".$this->sqlConditionJoins."
".$this->getConditionBuilder();
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($this->getConditionBuilder()->getParameters());
- $row = $statement->fetchArray();
- return $row['count'];
+
+ return $statement->fetchSingleColumn();
}
/**
//
if ($newLikeObject->objectUserID) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_like
WHERE objectTypeID = ?
AND objectID = ?
$this->parameters['targetObjectID'],
Like::LIKE
));
- $row = $statement->fetchArray();
+ $count = $statement->fetchSingleColumn();
- if ($row['count']) {
+ if ($count) {
// update received likes
$userEditor = new UserEditor(new User($newLikeObject->objectUserID));
$userEditor->updateCounters(array(
- 'likesReceived' => $row['count']
+ 'likesReceived' => $count
));
// add activity points
- UserActivityPointHandler::getInstance()->fireEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($newLikeObject->objectUserID => $row['count']));
+ UserActivityPointHandler::getInstance()->fireEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($newLikeObject->objectUserID => $count));
}
}
}
* @return boolean
*/
public static function isAlreadyInstalled($package) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_package
WHERE package = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($package));
- $row = $statement->fetchArray();
- return ($row['count'] ? true : false);
+ return $statement->fetchSingleColumn() > 0;
}
/**
// update option votes
$sql = "UPDATE wcf".WCF_N."_poll_option poll_option
SET poll_option.votes = (
- SELECT COUNT(*) AS count
+ SELECT COUNT(*)
FROM wcf".WCF_N."_poll_option_vote
WHERE optionID = poll_option.optionID
)
// update total count
$sql = "UPDATE wcf".WCF_N."_poll poll
SET poll.votes = (
- SELECT COUNT(DISTINCT userID) AS count
- FROM wcf".WCF_N."_poll_option_vote
- WHERE pollID = poll.pollID
+ SELECT COUNT(DISTINCT userID)
+ FROM wcf".WCF_N."_poll_option_vote
+ WHERE pollID = poll.pollID
)
WHERE poll.pollID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
* @return integer
*/
public static function countVirtualSessions($sessionID) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM ".static::getDatabaseTableName()."
WHERE sessionID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($sessionID));
- $row = $statement->fetchArray();
- return $row['count'];
+ return $statement->fetchSingleColumn();
}
}
$templateGroupFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templateGroupName);
if (empty($templateGroupFolderName)) $templateGroupFolderName = 'generic'.mb_substr(StringUtil::getRandomID(), 0, 8);
$originalTemplateGroupFolderName = $templateGroupFolderName;
-
+
// get unique template group name
$i = 1;
while (true) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_template_group
WHERE templateGroupName = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([$templateGroupName]);
- $row = $statement->fetchArray();
- if (!$row['count']) break;
+ if (!$statement->fetchSingleColumn()) break;
$templateGroupName = $originalTemplateGroupName . '_' . $i;
$i++;
}
-
+
// get unique folder name
$i = 1;
while (true) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_template_group
WHERE templateGroupFolderName = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([
FileUtil::addTrailingSlash($templateGroupFolderName)
]);
- $row = $statement->fetchArray();
- if (!$row['count']) break;
+ if (!$statement->fetchSingleColumn()) break;
$templateGroupFolderName = $originalTemplateGroupFolderName . '_' . $i;
$i++;
}
-
+
$templateGroupAction = new TemplateGroupAction([], 'create', [
'data' => [
'templateGroupName' => $templateGroupName,
* @see \wcf\data\DatabaseObjectList::countObjects()
*/
public function countObjects() {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user_group user_group,
wcf".WCF_N."_user_to_group user_to_group
WHERE user_to_group.groupID = user_group.groupID
AND user_group.showOnTeamPage = 1";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- $row = $statement->fetchArray();
- return $row['count'];
+
+ return $statement->fetchSingleColumn();
}
/**
* @return boolean
*/
public static function countIPFailures($ipAddress) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user_authentication_failure
WHERE ipAddress = ?
AND time > ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($ipAddress, TIME_NOW - USER_AUTHENTICATION_FAILURE_TIMEOUT));
+
return $statement->fetchColumn();
}
* @return boolean
*/
public static function countUserFailures($userID) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user_authentication_failure
WHERE userID = ?
AND time > ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($userID, TIME_NOW - USER_AUTHENTICATION_FAILURE_TIMEOUT));
+
return $statement->fetchColumn();
}
}
*/
public function getGroupedUserList() {
// resolve page count
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user_follow
WHERE followUserID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->parameters['userID']));
- $row = $statement->fetchArray();
- $pageCount = ceil($row['count'] / 20);
+ $pageCount = ceil($statement->fetchSingleColumn() / 20);
// get user ids
$sql = "SELECT userID
*/
public function getGroupedUserList() {
// resolve page count
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user_follow
WHERE userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->parameters['userID']));
- $row = $statement->fetchArray();
- $pageCount = ceil($row['count'] / 20);
+ $pageCount = ceil($statement->fetchSingleColumn() / 20);
// get user ids
$sql = "SELECT followUserID
*/
public function getGroupedUserList() {
// resolve page count
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user_profile_visitor
WHERE ownerID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->parameters['userID']));
- $row = $statement->fetchArray();
- $pageCount = ceil($row['count'] / 20);
+ $pageCount = ceil($statement->fetchSingleColumn() / 20);
// get user ids
$sql = "SELECT userID
WHERE package = 'com.woltlab.wcf'";
$statement = self::getDB()->prepareStatement($sql);
$statement->execute();
- $row = $statement->fetchArray();
- if (!$row['count']) {
+ if (!$statement->fetchSingleColumn()) {
if (empty($wcfPackageFile)) {
throw new SystemException('the essential package com.woltlab.wcf is missing.');
}
$conditionBuilder->add("objectTypeID = ?", array($objectTypeID));
}
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_clipboard_item
".$conditionBuilder;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditionBuilder->getParameters());
- $count = $statement->fetchArray();
- if ($count['count']) {
- return 1;
- }
-
- return 0;
+ return $statement->fetchSingleColumn() ? 1 : 0;
}
/**
$conditions->add("moderation_queue_to_user.isAffected = ?", array(1));
$conditions->add("moderation_queue.status IN (?)", array(array(ModerationQueue::STATUS_OUTSTANDING, ModerationQueue::STATUS_PROCESSING)));
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_moderation_queue_to_user moderation_queue_to_user
LEFT JOIN wcf".WCF_N."_moderation_queue moderation_queue
ON (moderation_queue.queueID = moderation_queue_to_user.queueID)
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $row = $statement->fetchArray();
- $count = $row['count'];
+ $count = $statement->fetchSingleColumn();
// update storage data
UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'outstandingModerationCount', $count);
$conditions->add("moderation_queue.time > ?", array(VisitTracker::getInstance()->getVisitTime('com.woltlab.wcf.moderation.queue')));
$conditions->add("(moderation_queue.time > tracked_visit.visitTime OR tracked_visit.visitTime IS NULL)");
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_moderation_queue_to_user moderation_queue_to_user
LEFT JOIN wcf".WCF_N."_moderation_queue moderation_queue
ON (moderation_queue.queueID = moderation_queue_to_user.queueID)
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $row = $statement->fetchArray();
- $count = $row['count'];
-
+ $count = $statement->fetchSingleColumn();
+
// update storage data
UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'unreadModerationCount', $count);
}
public function isAlreadyReported($objectType, $objectID) {
$objectTypeID = $this->getObjectTypeID($objectType);
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_moderation_queue
WHERE objectTypeID = ?
AND objectID = ?";
$objectTypeID,
$objectID
));
- $row = $statement->fetchArray();
- return ($row['count'] == 0 ? false : true);
+ return $statement->fetchSingleColumn() > 0;
}
/**
* @return boolean
*/
public function isAlreadyInstalled() {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_package
WHERE package = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->packageInfo['name']));
- $row = $statement->fetchArray();
- return ($row['count'] > 0) ? true : false;
+ return $statement->fetchSingleColumn() > 0;
}
/**
'%.'.Package::getAbbreviation($this->packageInfo['name'])
));
- return $statement->fetchColumn();
+ return $statement->fetchSingleColumn() > 0;
}
/**
$defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator(dirname(WCF_DIR)));
// check if there is already an application
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_package
WHERE packageDir = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array('../'));
- $row = $statement->fetchArray();
- if ($row['count']) {
+ if ($statement->fetchSingleColumn()) {
// use abbreviation
$defaultPath .= strtolower(Package::getAbbreviation($this->getPackage()->package)) . '/';
}
* @return boolean
*/
public static function findForm(PackageInstallationQueue $queue, $formName) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_package_installation_form
WHERE queueID = ?
AND formName = ?";
$queue->queueID,
$formName
));
- $row = $statement->fetchArray();
- return (bool)$row['count'];
+ return $statement->fetchSingleColumn() > 0;
}
/**
// validate category name
if (isset($data['categoryname'])) {
- $sql = "SELECT COUNT(categoryID) AS count
+ $sql = "SELECT COUNT(categoryID)
FROM wcf".WCF_N."_".$this->tableName."_category
WHERE categoryName = ?
AND objectTypeID = ?";
$data['categoryname'],
$objectTypeID
));
- $row = $statement->fetchArray();
- if (!$row) {
+
+ if (!$statement->fetchSingleColumn()) {
throw new SystemException("unknown category '".$data['categoryname']."' for acl object type '".$data['objecttype']."' given");
}
}
return;
}
- $sql = "SELECT COUNT(menuItemID) AS count
+ $sql = "SELECT COUNT(menuItemID)
FROM ".$this->application.WCF_N."_".$this->tableName."
WHERE menuItem = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($data['parentMenuItem']));
- $row = $statement->fetchArray();
- if (!$row['count']) {
+ if (!$statement->fetchSingleColumn()) {
throw new SystemException("Unable to find parent 'menu item' with name '".$data['parentMenuItem']."' for 'menu item' with name '".$data['menuItem']."'.");
}
}
// validate parent
if (!empty($data['parentCategoryName'])) {
- $sql = "SELECT COUNT(categoryID) AS count
+ $sql = "SELECT COUNT(categoryID)
FROM ".$this->application.WCF_N."_".$this->tableName."_category
WHERE categoryName = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($data['parentCategoryName']));
- $row = $statement->fetchArray();
- if (!$row['count']) {
+ if (!$statement->fetchSingleColumn()) {
throw new SystemException("Unable to find parent 'option category' with name '".$data['parentCategoryName']."' for category with name '".$data['categoryName']."'.");
}
}
*/
public function hasUninstall() {
$hasUninstallOptions = parent::hasUninstall();
- $sql = "SELECT COUNT(categoryID) AS count
+ $sql = "SELECT COUNT(categoryID)
FROM ".$this->application.WCF_N."_".$this->tableName."_category
WHERE packageID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->installation->getPackageID()));
- $categoryCount = $statement->fetchArray();
- return ($hasUninstallOptions || $categoryCount['count'] > 0);
+
+ return ($hasUninstallOptions || $statement->fetchSingleColumn() > 0);
}
/**
// call 'hasUninstall' event
EventHandler::getInstance()->fireAction($this, 'hasUninstall');
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM ".$this->application.WCF_N."_".$this->tableName."
WHERE packageID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->installation->getPackageID()));
- $installationCount = $statement->fetchArray();
- return $installationCount['count'];
+
+ return $statement->fetchSingleColumn() > 0;
}
/**
$tableName = SearchIndexManager::getTableName($objectType);
// check if table already exists
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_package_installation_sql_log
WHERE sqlTable = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($tableName));
- $row = $statement->fetchArray();
- if ($row['count']) {
+
+ if ($statement->fetchSingleColumn()) {
// table already exists
return false;
}
* @return integer
*/
protected function getCounter($date, $tableName, $dateColumnName) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM " . $tableName . "
WHERE " . $dateColumnName . " BETWEEN ? AND ?";
$statement = WCF::getDB()->prepareStatement($sql);
* @return integer
*/
protected function getTotal($date, $tableName, $dateColumnName) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM " . $tableName . "
WHERE " . $dateColumnName . " < ?";
$statement = WCF::getDB()->prepareStatement($sql);
// cache does not exist or is outdated
if ($data === null || $skipCache) {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user_notification
WHERE userID = ?
AND confirmTime = ?";
0
));
- $row = $statement->fetchArray();
- $this->notificationCount = $row['count'];
+ $this->notificationCount = $statement->fetchSingleColumn();
// update storage data
UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'userNotificationCount', serialize($this->notificationCount));
* @return integer
*/
public function countAllNotifications() {
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user_notification
WHERE userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array(WCF::getUser()->userID));
- $row = $statement->fetchArray();
- return $row['count'];
+ return $statement->fetchSingleColumn();
}
/**
}
}
- $sql = "SELECT COUNT(*) AS count
+ $sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user user
".$this->conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($this->conditions->getParameters());
- $row = $statement->fetchArray();
- $this->count = $row['count'];
+ $this->count = $statement->fetchSingleColumn();
}
/**
* @return boolean
*/
public static function isAvailableUsername($name) {
- $sql = "SELECT COUNT(username) AS count
+ $sql = "SELECT COUNT(username)
FROM wcf".WCF_N."_user
WHERE username = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($name));
- $row = $statement->fetchArray();
- return $row['count'] == 0;
+
+ return $statement->fetchSingleColumn() == 0;
}
/**
* @return boolean
*/
public static function isAvailableEmail($email) {
- $sql = "SELECT COUNT(email) AS count
+ $sql = "SELECT COUNT(email)
FROM wcf".WCF_N."_user
WHERE email = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($email));
- $row = $statement->fetchArray();
- return $row['count'] == 0;
+
+ return $statement->fetchSingleColumn() == 0;
}
/**