Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Executing SQL upon plugin install
How do you run an SQL query upon plugin install? The following works fine when my plugin is run from the cache, but the table isn’t created when the plugin is installed.
if (@txpinterface == 'admin') {
$sql = "CREATE TABLE IF NOT EXISTS ".safe_pfx('jmd_rate')."(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
votes INT NOT NULL,
value INT NOT NULL,
used_ips LONGTEXT NULL
);";
safe_query($sql);
}
Offline
Offline
#3 2008-03-03 02:30:01
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Executing SQL upon plugin install
I wouldn’t recommend that snippet as-is: you’d be running the query on every page load.
Offline
Re: Executing SQL upon plugin install
So what do you think I should do? I wasn’t planning on building an admin interface yet, but would that be the only way to create a table?
Offline
#5 2008-03-03 02:42:41
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Executing SQL upon plugin install
Put the query inside a callback, then link to it from the plugin’s help doc, an “install” link.
Offline