Up to v2.0, accessing the nucleus tables was just a matter of performing an SQL query on one of the nucleus_ tables. Since it is possible to use a custom table name in Nucleus versions >2.0, some precautions are needed in plugin development:
nucleus_item, use the global function sql_table('item') to generate the prefixed tablename1 (true) when supportsFeature('SqlTablePrefix') is called on it. If it doesn't, you won't be able to load the plugin on Nucleus versions > 2.0 when a custom prefix has been set (as a precaution)Note that the sql_table global function in not available in Nucleus versions up to v2.0. If you use this method and want your plugin to work on Nucleus versions <= 2.0, add the following snippet of code on top of your plugin class:
<?php
// plugin needs to work on Nucleus versions <=2.0 as well
if (!function_exists('sql_table'))
{
function sql_table($name) {
return 'nucleus_' . $name;
}
}
class NP_HelloWorld extends NucleusPlugin {
...
}
?>
If your plugin needs database tables of it's own, you should create then in the install method and remove them in the unInstall method.
Some pointers
nucleus_plug_plugname to avoid conflicts with other plugins. Generate them through sql_table('plug_plugname') to make it work with custom prefixesmysql_query()sql_connect() at the end of your function. It might also be good to do this from the constructor, to avoid reconnecting constantly. You could then save your link identifier in $this->db and pass that along with every query.getTableList() method to make sure your table gets backupped when using the backup function.