本文整理汇总了PHP中phpbb\db\driver\driver_interface::sql_affectedrows方法的典型用法代码示例。如果您正苦于以下问题:PHP driver_interface::sql_affectedrows方法的具体用法?PHP driver_interface::sql_affectedrows怎么用?PHP driver_interface::sql_affectedrows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpbb\db\driver\driver_interface
的用法示例。
在下文中一共展示了driver_interface::sql_affectedrows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: page_header_after
public function page_header_after($event)
{
$context = $this->phpbb_container->get('template_context');
$rootref =& $context->get_root_ref();
if (isset($this->config['menu_enabled']) && $this->config['menu_enabled']) {
$sql = 'SELECT *
FROM ' . $this->menu_colors;
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
if ($this->db->sql_affectedrows()) {
$this->template->assign_vars(array('S_MENU_COLOR' => $row['color_name'], 'S_MENU_FONT_COLOR' => $row['color_text'], 'S_MENU_FONT_COLOR_HOVER' => $row['color_text_hover'], 'S_MENU_DECORATION' => $row['color_text_hover_decor'], 'S_MENU_WEIGHT' => $row['color_text_weight'], 'S_MENU_SEARCH' => $row['color_display_search'], 'S_MENU_TEXT_TRANSFORM' => $row['color_text_transform'], 'S_MENU_ALIGN' => $row['color_align']));
$sql = 'SELECT *
FROM ' . $this->menu_buttons . '
WHERE button_display = 1
AND parent_id = 0
ORDER BY left_id';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) {
if ($row['button_only_registered'] && $this->user->data['user_id'] == ANONYMOUS || $row['button_only_guest'] && $this->user->data['user_id'] != ANONYMOUS) {
continue;
}
if (preg_match("/\\{(.*)\\}/", $row['button_url'])) {
$brackets = array("{", "}");
$var_name = strtoupper(str_replace($brackets, '', $row['button_url']));
$row['button_url'] = $rootref[$var_name];
}
if (preg_match("/\\{(.*)\\}/", $row['button_name'])) {
$brackets = array("{L_", "}");
$var_name = strtoupper(str_replace($brackets, '', $row['button_name']));
$row['button_name'] = $this->user->lang[$var_name];
}
$this->template->assign_block_vars('buttons', array('ID' => $row['button_id'], 'URL' => $row['button_url'], 'NAME' => $row['button_name'], 'EXTERNAL' => $row['button_external']));
$sub_sql = 'SELECT *
FROM ' . $this->menu_buttons . '
WHERE button_display = 1
AND parent_id = ' . $row['button_id'] . '
ORDER BY left_id';
$sub_result = $this->db->sql_query($sub_sql);
while ($sub_row = $this->db->sql_fetchrow($sub_result)) {
if ($sub_row['button_only_registered'] && $this->user->data['user_id'] == ANONYMOUS || $sub_row['button_only_guest'] && $this->user->data['user_id'] != ANONYMOUS) {
continue;
}
if (preg_match("/\\{(.*)\\}/", $sub_row['button_url'])) {
$brackets = array("{", "}");
$var_name = strtoupper(str_replace($brackets, '', $sub_row['button_url']));
$sub_row['button_url'] = $rootref[$var_name];
}
if (preg_match("/\\{(.*)\\}/", $sub_row['button_name'])) {
$brackets = array("{L_", "}");
$var_name = strtoupper(str_replace($brackets, '', $sub_row['button_name']));
$sub_row['button_name'] = $this->user->lang[$var_name];
}
$this->template->assign_block_vars('buttons.sub', array('ID' => $sub_row['button_id'], 'URL' => $sub_row['button_url'], 'NAME' => $sub_row['button_name'], 'EXTERNAL' => $sub_row['button_external']));
}
$this->db->sql_freeresult($sub_result);
}
$this->db->sql_freeresult($result);
}
}
}
示例2: track
/**
* Track an object.
*
* @param int $type Object type
* @param int $id Object id
* @param bool|int $time Optional track time to use, if none is given
* the value from time() is used.
*/
public function track($type, $id, $time = false)
{
// Ignore
$this->get_track_cookie();
// Cookie storage method
if (!$this->user->data['is_registered']) {
$this->track_cookie($type, $id, $time);
return;
}
if ($this->get_track($type, $id, true) >= ($time === false ? time() : (int) $time)) {
return;
}
$sql = 'UPDATE ' . $this->sql_table . '
SET track_time = ' . ($time === false ? time() : (int) $time) . '
WHERE track_type = ' . (int) $type . '
AND track_id = ' . (int) $id . '
AND track_user_id = ' . (int) $this->user->data['user_id'];
$this->db->sql_query($sql);
if (!$this->db->sql_affectedrows()) {
$sql_ary = array('track_type' => (int) $type, 'track_id' => (int) $id, 'track_user_id' => (int) $this->user->data['user_id'], 'track_time' => $time === false ? time() : (int) $time);
$this->db->sql_return_on_error(true);
$this->db->sql_query('INSERT INTO ' . $this->sql_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary));
$this->db->sql_return_on_error();
}
$this->store[$type][$id] = $time === false ? time() : (int) $time;
}
示例3: move
/**
* Update BBCode order fields in the db on move up/down
*
* @param string $action The action move_up|move_down
* @return null
* @access public
*/
public function move($action)
{
$bbcode_id = $this->request->variable('id', 0);
if (!check_link_hash($this->request->variable('hash', ''), $action . $bbcode_id)) {
trigger_error($this->user->lang('FORM_INVALID'), E_USER_WARNING);
}
// Get current order
$sql = 'SELECT bbcode_order
FROM ' . BBCODES_TABLE . "\n\t\t\tWHERE bbcode_id = {$bbcode_id}";
$result = $this->db->sql_query($sql);
$current_order = (int) $this->db->sql_fetchfield('bbcode_order');
$this->db->sql_freeresult($result);
// First one can't be moved up
if ($current_order <= 1 && $action == 'move_up') {
return;
}
$order_total = $current_order * 2 + $this->increment($action);
// Update the db
$sql = 'UPDATE ' . BBCODES_TABLE . '
SET bbcode_order = ' . $order_total . ' - bbcode_order
WHERE ' . $this->db->sql_in_set('bbcode_order', array($current_order, $current_order + $this->increment($action)));
$this->db->sql_query($sql);
// Resync bbcode_order
$this->resynchronize_bbcode_order();
// return a JSON response if this was an AJAX request
if ($this->request->is_ajax()) {
$json_response = new \phpbb\json_response();
$json_response->send(array('success' => (bool) $this->db->sql_affectedrows()));
}
}
示例4: update_session
/**
* Update the users session in the table.
*/
public function update_session()
{
if ($this->user->data['user_id'] != ANONYMOUS) {
$wwh_data = array('user_id' => $this->user->data['user_id'], 'user_ip' => $this->user->ip, 'username' => $this->user->data['username'], 'username_clean' => $this->user->data['username_clean'], 'user_colour' => $this->user->data['user_colour'], 'user_type' => $this->user->data['user_type'], 'viewonline' => $this->user->data['session_viewonline'], 'wwh_lastpage' => time());
$this->db->sql_return_on_error(true);
$sql = 'UPDATE ' . WWH_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $wwh_data) . '
WHERE user_id = ' . (int) $this->user->data['user_id'] . "\n\t\t\t\t\tOR (user_ip = '" . $this->db->sql_escape($this->user->ip) . "'\n\t\t\t\t\t\tAND user_id = " . ANONYMOUS . ')';
$result = $this->db->sql_query($sql);
$this->db->sql_return_on_error(false);
if ((bool) $result === false) {
// database does not exist yet...
return;
}
$sql_affectedrows = (int) $this->db->sql_affectedrows();
if ($sql_affectedrows != 1) {
if ($sql_affectedrows > 1) {
// Found multiple matches, so we delete them and just add one
$sql = 'DELETE FROM ' . WWH_TABLE . '
WHERE user_id = ' . (int) $this->user->data['user_id'] . "\n\t\t\t\t\t\t\tOR (user_ip = '" . $this->db->sql_escape($this->user->ip) . "'\n\t\t\t\t\t\t\t\tAND user_id = " . ANONYMOUS . ')';
$this->db->sql_query($sql);
$this->db->sql_query('INSERT INTO ' . WWH_TABLE . ' ' . $this->db->sql_build_array('INSERT', $wwh_data));
}
if ($sql_affectedrows == 0) {
// No entry updated. Either the user is not listed yet, or has opened two links in the same time
$sql = 'SELECT 1 as found
FROM ' . WWH_TABLE . '
WHERE user_id = ' . (int) $this->user->data['user_id'] . "\n\t\t\t\t\t\t\tOR (user_ip = '" . $this->db->sql_escape($this->user->ip) . "'\n\t\t\t\t\t\t\t\tAND user_id = " . ANONYMOUS . ')';
$result = $this->db->sql_query($sql);
$found = (int) $this->db->sql_fetchfield('found');
$this->db->sql_freeresult($result);
if (!$found) {
// He wasn't listed.
$this->db->sql_query('INSERT INTO ' . WWH_TABLE . ' ' . $this->db->sql_build_array('INSERT', $wwh_data));
}
}
}
} else {
$this->db->sql_return_on_error(true);
$sql = 'SELECT user_id
FROM ' . WWH_TABLE . "\n\t\t\t\tWHERE user_ip = '" . $this->db->sql_escape($this->user->ip) . "'";
$result = $this->db->sql_query_limit($sql, 1);
$this->db->sql_return_on_error(false);
if ((bool) $result === false) {
// database does not exist yet...
return;
}
$user_logged = (int) $this->db->sql_fetchfield('user_id');
$this->db->sql_freeresult($result);
if (!$user_logged) {
$wwh_data = array('user_id' => $this->user->data['user_id'], 'user_ip' => $this->user->ip, 'username' => $this->user->data['username'], 'username_clean' => $this->user->data['username_clean'], 'user_colour' => $this->user->data['user_colour'], 'user_type' => $this->user->data['user_type'], 'viewonline' => 1, 'wwh_lastpage' => time());
$this->db->sql_query('INSERT INTO ' . WWH_TABLE . ' ' . $this->db->sql_build_array('INSERT', $wwh_data));
}
}
$this->db->sql_return_on_error(false);
}
示例5: move
/**
* {@inheritDoc}
*/
public function move($group_id, $delta)
{
$delta = (int) $delta;
if (!$delta) {
return false;
}
$move_up = $delta > 0 ? true : false;
$current_value = $this->get_group_value($group_id);
if ($current_value != self::GROUP_DISABLED) {
$this->db->sql_transaction('begin');
// First we move all groups between our current value and the target value up/down 1,
// so we have a gap for our group to move.
$sql = 'UPDATE ' . GROUPS_TABLE . '
SET group_legend = group_legend' . ($move_up ? ' + 1' : ' - 1') . '
WHERE group_legend > ' . self::GROUP_DISABLED . '
AND group_legend' . ($move_up ? ' >= ' : ' <= ') . ($current_value - $delta) . '
AND group_legend' . ($move_up ? ' < ' : ' > ') . $current_value;
$this->db->sql_query($sql);
// Because there might be fewer groups above/below the group than we wanted to move,
// we use the number of changed groups, to update the group.
$delta = (int) $this->db->sql_affectedrows();
if ($delta) {
// And now finally, when we moved some other groups and built a gap,
// we can move the desired group to it.
$sql = 'UPDATE ' . GROUPS_TABLE . '
SET group_legend = group_legend ' . ($move_up ? ' - ' : ' + ') . $delta . '
WHERE group_id = ' . (int) $group_id;
$this->db->sql_query($sql);
$this->db->sql_transaction('commit');
return true;
}
$this->db->sql_transaction('commit');
}
return false;
}
示例6: delete_attachments_from_db
/**
* Delete attachments from database table
*/
protected function delete_attachments_from_db()
{
/**
* Perform additional actions before attachment(s) deletion
*
* @event core.delete_attachments_before
* @var string mode Variable containing attachments deletion mode, can be: post|message|topic|attach|user
* @var mixed ids Array or comma separated list of ids corresponding to the mode
* @var bool resync Flag indicating if posts/messages/topics should be synchronized
* @var string sql_id The field name to collect/delete data for depending on the mode
* @var array post_ids Array with post ids for deleted attachment(s)
* @var array topic_ids Array with topic ids for deleted attachment(s)
* @var array message_ids Array with private message ids for deleted attachment(s)
* @var array physical Array with deleted attachment(s) physical file(s) data
* @since 3.1.7-RC1
*/
$vars = array('mode', 'ids', 'resync', 'sql_id', 'post_ids', 'topic_ids', 'message_ids', 'physical');
extract($this->dispatcher->trigger_event('core.delete_attachments_before', compact($vars)));
// Delete attachments
$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
WHERE ' . $this->db->sql_in_set($this->sql_id, $this->ids);
$sql .= $this->sql_where;
$this->db->sql_query($sql);
$this->num_deleted = $this->db->sql_affectedrows();
}
示例7: set_user_categories
/**
* {@inheritdoc}
*/
public function set_user_categories($forum_id)
{
// Set the collapsed category data array
$this->set_collapsed_categories($forum_id);
// Update the db with json encoded array of collapsed category data
if ($this->user->data['is_registered']) {
$sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\tSET collapsible_categories = '" . $this->db->sql_escape(json_encode($this->collapsed_categories)) . "'\n\t\t\t\tWHERE user_id = " . (int) $this->user->data['user_id'];
$this->db->sql_query($sql);
// There was an error updating the user's data
if (!$this->db->sql_affectedrows()) {
return false;
}
}
// Set a cookie with the collapsed category data and return true
return $this->set_cookie_categories($forum_id);
}
示例8: move_module_horizontal
/**
* Move module horizontally
*
* @param int $module_id Module ID
* @param array $module_data Module data array
* @param int $move_action The move action
*/
public function move_module_horizontal($module_id, $module_data, $move_action)
{
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order + 1
WHERE module_order >= ' . (int) $module_data['module_order'] . '
AND module_column = ' . (int) ($module_data['module_column'] + $move_action);
$this->db->sql_query($sql);
$updated = $this->db->sql_affectedrows();
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_column = ' . (int) ($module_data['module_column'] + $move_action) . '
WHERE module_id = ' . (int) $module_id;
$this->db->sql_query($sql);
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order - 1
WHERE module_order >= ' . (int) $module_data['module_order'] . '
AND module_column = ' . (int) $module_data['module_column'];
$this->db->sql_query($sql);
// the module that needs to moved is in the last row
if (!$updated) {
$sql = 'SELECT MAX(module_order) as new_order
FROM ' . PORTAL_MODULES_TABLE . '
WHERE module_order < ' . (int) $module_data['module_order'] . '
AND module_column = ' . (int) ($module_data['module_column'] + $move_action);
$this->db->sql_query($sql);
$new_order = $this->db->sql_fetchfield('new_order') + 1;
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = ' . (int) $new_order . '
WHERE module_id = ' . (int) $module_id;
$this->db->sql_query($sql);
}
}
示例9: set_atomic
/**
* Sets a configuration option's value only if the old_value matches the
* current configuration value or the configuration value does not exist yet.
*
* @param string $key The configuration option's name
* @param mixed $old_value Current configuration value or false to ignore
* the old value
* @param string $new_value New configuration value
* @param bool $use_cache Whether this variable should be cached or if it
* changes too frequently to be efficiently cached
* @return bool True if the value was changed, false otherwise
*/
public function set_atomic($key, $old_value, $new_value, $use_cache = true)
{
$sql = 'UPDATE ' . $this->table . "
SET config_value = '" . $this->db->sql_escape($new_value) . "'
WHERE config_name = '" . $this->db->sql_escape($key) . "'";
if ($old_value !== false)
{
$sql .= " AND config_value = '" . $this->db->sql_escape($old_value) . "'";
}
$result = $this->db->sql_query($sql);
if (!$this->db->sql_affectedrows($result) && isset($this->config[$key]))
{
return false;
}
if (!isset($this->config[$key]))
{
$sql = 'INSERT INTO ' . $this->table . ' ' . $this->db->sql_build_array('INSERT', array(
'config_name' => $key,
'config_value' => $new_value,
'is_dynamic' => ($use_cache) ? 0 : 1));
$this->db->sql_query($sql);
}
if ($use_cache)
{
$this->cache->destroy('config');
}
$this->config[$key] = $new_value;
return true;
}
示例10: delete_subscription
/**
* Delete a subscription
*
* @param string $item_type Type identifier of the subscription
* @param int $item_id The id of the item
* @param string $method The method of the notification e.g. 'board', 'email', or 'jabber'
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
*/
public function delete_subscription($item_type, $item_id = 0, $method = null, $user_id = false)
{
if ($method === null)
{
foreach ($this->get_default_methods() as $method_name)
{
$this->delete_subscription($item_type, $item_id, $method_name, $user_id);
}
return;
}
$user_id = $user_id ?: $this->user->data['user_id'];
$sql = 'UPDATE ' . $this->user_notifications_table . "
SET notify = 0
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
AND item_id = " . (int) $item_id . '
AND user_id = ' .(int) $user_id . "
AND method = '" . $this->db->sql_escape($method) . "'";
$this->db->sql_query($sql);
if (!$this->db->sql_affectedrows())
{
$sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' .
$this->db->sql_build_array('INSERT', array(
'item_type' => $item_type,
'item_id' => (int) $item_id,
'user_id' => (int) $user_id,
'method' => $method,
'notify' => 0,
));
$this->db->sql_query($sql);
}
}
示例11: set_topic_visibility
/**
* Set topic visibility
*
* Allows approving (which is akin to undeleting/restore) or soft deleting an entire topic.
* Calls set_post_visibility as needed.
*
* Note: By default, when a soft deleted topic is restored. Only posts that
* were approved at the time of soft deleting, are being restored.
* Same applies to soft deleting. Only approved posts will be marked
* as soft deleted.
* If you want to update all posts, use the force option.
*
* @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE}
* @param $topic_id mixed Topic ID to act on
* @param $forum_id int Forum where $topic_id is found
* @param $user_id int User performing the action
* @param $time int Timestamp when the action is performed
* @param $reason string Reason why the visibilty was changed.
* @param $force_update_all bool Force to update all posts within the topic
* @return array Changed topic data, empty array if an error occured.
*/
public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false)
{
if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE)))
{
return array();
}
if (!$force_update_all)
{
$sql = 'SELECT topic_visibility, topic_delete_time
FROM ' . $this->topics_table . '
WHERE topic_id = ' . (int) $topic_id;
$result = $this->db->sql_query($sql);
$original_topic_data = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$original_topic_data)
{
// The topic does not exist...
return array();
}
}
// Note, we do not set a reason for the posts, just for the topic
$data = array(
'topic_visibility' => (int) $visibility,
'topic_delete_user' => (int) $user_id,
'topic_delete_time' => ((int) $time) ?: time(),
'topic_delete_reason' => truncate_string($reason, 255, 255, false),
);
$sql = 'UPDATE ' . $this->topics_table . '
SET ' . $this->db->sql_build_array('UPDATE', $data) . '
WHERE topic_id = ' . (int) $topic_id;
$this->db->sql_query($sql);
if (!$this->db->sql_affectedrows())
{
return array();
}
if (!$force_update_all && $original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED)
{
// If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion.
$this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility'], $original_topic_data['topic_delete_time']);
}
else if (!$force_update_all && $original_topic_data['topic_visibility'] == ITEM_APPROVED && $visibility == ITEM_DELETED)
{
// If we're soft deleting a topic we only mark approved posts as soft deleted.
$this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility']);
}
else
{
$this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true);
}
return $data;
}
示例12: delete
/**
* Deletes an object identified by $this->sql_id_field
*
* @return int rows deleted
*/
public function delete()
{
$sql = 'DELETE FROM ' . $this->sql_table . '
WHERE ' . $this->sql_id_field . ' = ' . $this->{$this->sql_id_field};
$this->db->sql_query($sql);
// Unset the sql indentifier field
unset($this->{$this->sql_id_field});
return $this->db->sql_affectedrows();
}
示例13: update_board_announcement_status
/**
* Close an announcement for a registered user
*
* @return bool True if successful, false otherwise
* @access protected
*/
protected function update_board_announcement_status()
{
// Set announcement status to 0 for registered user
$sql = 'UPDATE ' . USERS_TABLE . '
SET board_announcements_status = 0
WHERE user_id = ' . (int) $this->user->data['user_id'] . '
AND user_type <> ' . USER_IGNORE;
$this->db->sql_query($sql);
return (bool) $this->db->sql_affectedrows();
}
示例14: delete_page
/**
* Delete a page
*
* @param int $page_id The page identifier to delete
* @return bool True if row was deleted, false otherwise
* @throws \phpbb\pages\exception\out_of_bounds
* @access public
*/
public function delete_page($page_id)
{
// Remove any existing page link data for this page
// An exception will be thrown if page identifier is invalid
$this->remove_page_links($page_id);
// Delete the page from the database
$sql = 'DELETE FROM ' . $this->pages_table . '
WHERE page_id = ' . (int) $page_id;
$this->db->sql_query($sql);
// Return true/false if a page was deleted
return (bool) $this->db->sql_affectedrows();
}
示例15: set_tags_enabled_in_all_forums
/**
* en/disables tagging engine in all forums (not categories and links).
*
* @param boolean $enable true to enable and false to disabl the engine
* @return number of affected forums (should be the count of all forums (type FORUM_POST ))
*/
private function set_tags_enabled_in_all_forums($enable)
{
$sql_ary = array('rh_topictags_enabled' => $enable ? 1 : 0);
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
WHERE forum_type = ' . FORUM_POST . '
AND rh_topictags_enabled = ' . ($enable ? '0' : '1');
$this->db->sql_query($sql);
$affected_rows = $this->db->sql_affectedrows();
$this->calc_count_tags();
return (int) $affected_rows;
}