Exemple #1
0
 /**
  * Generates the SQL to delete a record from a database table, then executes it
  *
  * @param	string	The system's table prefix
  * @param	string	The name of the database table to be affected (do not include TABLE_PREFIX in your argument)
  * @param	string	Specify the WHERE condition for the DELETE here. For example, 'userid > 10 AND posts < 50'
  * @param	boolean	Whether or not to actually run the query
  *
  * @return	integer	The number of records deleted
  */
 function db_delete($tableprefix, $table, $condition = '', $doquery = true)
 {
     $sql = "DELETE FROM {$tableprefix}{$table} WHERE {$condition}";
     if ($doquery) {
         $this->dbobject->query_write($sql);
         return $this->dbobject->affected_rows();
     } else {
         echo "<pre>{$sql}<hr /></pre>";
         return 12345;
     }
 }
 public function EmptyFolderPM()
 {
     if ($this->vbulletin->options['dle_onoff'] && $this->vbulletin->options['dle_pm']) {
         $this->_db_connect();
         $user_name = $this->db->escape_string($this->vbulletin->userinfo['username']);
         $user_id = $this->db->query_first("SELECT user_id FROM " . USERPREFIX . "_users WHERE name='{$user_name}'");
         if ($user_id) {
             if ($this->vbulletin->GPC['folderid'] == -1) {
                 $this->db->query_write("DELETE FROM " . USERPREFIX . "_pm WHERE folder='outbox' AND user={$user_id['user_id']}");
             } else {
                 $this->db->query_write("DELETE FROM " . USERPREFIX . "_pm WHERE folder='inbox' AND user={$user_id['user_id']}");
             }
             if ($num_rows = $this->db->affected_rows()) {
                 $pm_unread = '';
                 if ($this->vbulletin->GPC['folderid'] != -1) {
                     $pm_unread = ", pm_unread=0";
                 }
                 $this->db->query_write("UPDATE " . USERPREFIX . "_users SET pm_all=IF(pm_all-{$num_rows}<=0, 0, pm_all-{$num_rows}){$pm_unread} WHERE user_id=" . $user_id['user_id']);
             }
         }
         $this->_db_disconnect();
     }
 }