MyBB Community Forums

Full Version: Need help with database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I currently have a table named mybb_servers with a category of status inside it which just holds off.

I want to write a script that when its run, changes whats held to ono.

So far I have:

// Require the Global file

define('IN_MYBB', 1);
require_once "./global.php";

// Write to DB

$db->write_query("INSERT INTO ".TABLE_PREFIX."servers (status) VALUES
(ono);

I have not tested this yet in case it messes anything up, could someone please just let me know if this is the correct method on doing it?

Thanks in advance.
@Nineteh, you didn't close quote and bracket:

$db->write_query("INSERT INTO ".TABLE_PREFIX."servers (status) VALUES (ono)");

the correct query you can use is:

$db->insert_query("servers", array("status" => "ono"));
Chack you're a genius! I actually saw this in the methods but didn't think to use it. Thankyou buddy!
Hello, I required a great bit of code from a fellow member which works great:

// Require the Global file

define('IN_MYBB', 1);
require_once "./global.php";

// Write to DB

if ($mybb->user['usergroup'] == 10 || $mybb->user['usergroup'] == 4) {
	
	$db->insert_query("servers", array("status" => "ono"));
}

?>

The only problem I am having is that instead of overwriting the current 'off' thats stored, it creates a new one. Is there are a way to delete everything inside the category 'status' before it creates a new one?

Thanks in advance.

EDIT: Would this work?

$db->delete_query('servers', '*', "status = 'off'");
Or maybe this?
$db->drop_column("servers", "status");
@Ninethe you can use update method:

    $query = $db->simple_select("servers", "*");
    if($db->num_rows($query) > 0) {
        $db->update_query("servers", array("status" => "ono"));
    } else {
        $db->insert_query("servers", array("status" => "ono"));
    }

WARNING!
I don't know your database, so I don't know if this code will work