Log in

View Full Version : Emptying a table?


Cybertims
09-20-2006, 12:49 PM
Is there an easy way to create a link that when clicked will empty a database table??

I use the ChatBox light and want MODS to be able to prune it easily without actually having to have access to the Database.

The table is called chatboxlite_shout

Cheers in advance.

RS_Jelle
09-20-2006, 01:53 PM
That's the TRUNCATE (http://dev.mysql.com/doc/refman/5.0/en/truncate.html) command ;)

TRUNCATE TABLE `chatboxlite_shout`;

Cybertims
09-20-2006, 02:03 PM
That's the TRUNCATE (http://dev.mysql.com/doc/refman/5.0/en/truncate.html) command ;)

TRUNCATE TABLE `chatboxlite_shout`;

Cheers for that.....but to be honest it doesnt really help me too much as I have no idea how to use this to create a link that would enable my MODS to empty this said table....thanks though.

RS_Jelle
09-22-2006, 04:46 PM
In vBulletin sql code it becomes:

$result = $db->query_write("TRUNCATE TABLE `" . TABLE_PREFIX . "chatboxlite_shout`");

You need to put it on a seperate page (for example yourmod.php?do=empty) and check for the permissions (so normal users can't use it). Those things are explained here (https://vborg.vbsupport.ru/showthread.php?t=98009) ;)

rogersnm
09-22-2006, 05:37 PM
If you want it in full do something like:
1) Make a file called chatbox.php
2) Put this as it's contents:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'chatbox');

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array();

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'empty';
}


if ($_REQUEST['do'] == 'empty')
{
if (can_moderate())
{
$vbulletin->db->query_write("TRUNCATE TABLE chatboxlite_shout");
}
else
{
print_no_permission();
}
}
?>

and then only people who can moderate will be able to use it.