MyBB-Plugins Forums
problems with query inside activation in plugin - Printable Version

+- MyBB-Plugins Forums (http://forums.mybb-plugins.com)
+-- Forum: Archived Forums (http://forums.mybb-plugins.com/Forum-Archived-Forums)
+--- Forum: MyBB 1.4.x (http://forums.mybb-plugins.com/Forum-MyBB-1-4-x)
+---- Forum: General (http://forums.mybb-plugins.com/Forum-General)
+---- Thread: problems with query inside activation in plugin (/Thread-problems-with-query-inside-activation-in-plugin)



problems with query inside activation in plugin - jo3_sum - 08-18-2009

My settings might be wrong but this is what happens:
Code:
MyBB
MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
    1146 - Table 'mybb_db.mybb_mybb_settinggroups' doesn't exist
Query:
    INSERT INTO mybb_mybb_settinggroups (`gid`,`name`,`title`,`description`,`disporder`,`isdefault`) VALUES ('NULL','playlist_usrs','Playlist Users','Playlist user information','88','no')

Code:
function playlist_activate(){
    global $db, $mybb;

    require "../inc/adminfunctions_templates.php";
    $playlist_group = array(
    "gid" => "NULL",
    "name" => "playlist_usrs",
    "title" => "Playlist Users",
    "description" => "Playlist user information",
    "disporder" => "88",
    "isdefault" => "no",
    );

    $db->insert_query(TABLE_PREFIX."settinggroups", $playlist_group);
    $gid = $db->insert_id();

    $playlist_setting_1 = array(
    "sid" => "NULL",
    "name" => "Playlist enable",
    "title" => "Enable",
    "description" => "Would you like to enable Playlist?",
    "optionscode" => "yesno",
    "value" => "yes",
    "disporder" => "1",
    "gid" => intval($gid),
    );

    $db->insert_query(TABLE_PREFIX."settings", $playlist_setting_1);

    $playlist_setting_2 = array(
    "sid" => "NULL",
    "name" => "playlist_setting",
    "title" => "Playlist Setting",
    "description" => "Playlist ID",
    "optionscode" => "text",
    "value" => "68471617",
    "disporder" => "2",
    "gid" => intval($gid),
    );

    $db->insert_query(TABLE_PREFIX."settings", $playlist_setting_2);
}



RE: problems with query inside activation in plugin - Diogo Parrinha - 08-18-2009

You don't need:
require "../inc/adminfunctions_templates.php";
unless you are going to use the find replace templates function
and use MYBB_ROOT."inc/....
To fix your error, remove TABLE_PREFIX.
It's only needed when you're running queries directly, not when using functions like update_query, insert_query, delete_query, etc. These add the prefix since MyBB 1.4 Smile