Plugin Installer - Install & Upgrade
Before reading this, you may want to look at the Schema class, as all queries in plugin installer must use this class for database compatibility.
Your plugin might need to store or retrieve data from a table. For that purpose you have to specify the required schema.
Create a folder named 'install' in your plugin directory.
2.0.php are installation files. There is an installation file for each plugin version. Codoforum uses the file names to determine which file to execute first, and in what order they will be executed.
Note: If you have version 1.0 and are updating to version 1.1, the 1.1.php file will not be executed if there was no 1.0.php file in the 1.0 release. For this reason, it is good practice to have an update file for each version, even if there is no change in that version. You can just use an empty file or a file with a comment line.
Codoforum uses the PHP
version_compare function to execute the correct update files. Familiarize yourself with this function as your version strings need to adhere to the conventions of this function.
For example, the install/update files for version 1.3 of this example include:
//empty file since there are no changes to table.
Schema::table(PREFIX . 'messages', function($table)
DB::insert('INSERT INTO '.PREFIX.'messages (id,message) VALUES (1,'Hello world!');
DB::update('UPDATE '.PREFIX.'messages SET message='Hello again' WHERE id=1');
DB::insert('INSERT INTO '.PREFIX.'messages (id,message) VALUES (2,'How are you ?');
Note: Make sure you use the
PREFIX constant before every table name
PREFIX constant is the database prefix defined at the time of codoforum installation