MyBB Community Forums
Need help with database - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: 1.8 Support (https://community.mybb.com/forum-175.html)
+--- Forum: General Support (https://community.mybb.com/forum-176.html)
+--- Thread: Need help with database (/thread-179058.html)



Need help with database - Nineteh - 2015-09-13

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.


RE: Writing to the database - chack1172 - 2015-09-13

@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"));



RE: Need help with database - Nineteh - 2015-09-13

Chack you're a genius! I actually saw this in the methods but didn't think to use it. Thankyou buddy!


Database : Need Help - Nineteh - 2015-09-13

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");



RE: Need help with database - chack1172 - 2015-09-14

@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