Hi there,
Quick one here. I was just wondering how I go about creating a table to use in an extension that I am making?
I tried this code :
//------------------------------------
// Activate Extension
//------------------------------------
function activate_extension()
{
global $DB;
$DB->query($DB->insert_string('exp_extensions',
array(
'extension_id' => '',
'class' => $this->classname,
'method' => "redirect_upon_logout",
'hook' => "member_member_logout",
'settings' => $default_settings,
'priority' => 10,
'version' => $this->version,
'enabled' => "y"
)
)
);
$DB->query("CREATE TABLE IF NOT EXISTS `exp_logout_redirect_url` (
`member_id` INT NULL ,
`url` VARCHAR(300) NULL);"
);
foreach ($sql as $query)
{
$DB->query($query);
}
return true;
}
// END
in my extension but every-time I go to the Extensions Manager I just get a blank page show up so I must have done something wrong somewhere!! 😊
If I comment out the SQL part then it works fine. So if I do this :
//------------------------------------
// Activate Extension
//------------------------------------
function activate_extension()
{
global $DB;
$DB->query($DB->insert_string('exp_extensions',
array(
'extension_id' => '',
'class' => $this->classname,
'method' => "redirect_upon_logout",
'hook' => "member_member_logout",
'settings' => $default_settings,
'priority' => 10,
'version' => $this->version,
'enabled' => "y"
)
)
);
/* $DB->query("CREATE TABLE IF NOT EXISTS `exp_logout_redirect_url` (
`member_id` INT NULL ,
`url` VARCHAR(300) NULL);"
);
foreach ($sql as $query)
{
$DB->query($query);
}
return true;*/
}
// END
it loads the Extensions Manager page correctly. How do I go about adding in a table for use in my extension?
I couldn’t find much in the documents about it anywhere.
HELP!!! 😊
Best wishes,
Mark
Okay my boob!! Have fixed the problem now. I had a couple of little things wrong with the database insert code above but my main problem was that when I was using PHPMyAdmin on my DEV server even though I clicked to view the list of tables in the ExpressionEngine database it was not updating the left hand list of tables and so I was thinking that it wasn’t being added whereas it really was!!!
On a side note to all of this, can a plugin write to a database table? I have tried making a very very simple plugin which when called writes to the database table that I created with the extension but it just makes the page go blank when I view the template in the front end.
it must be possible to do this from a plugin mustn’t it?
Thanks for any help with this.
Best wishes,
Mark
Hi Erin,
Yeah, thanks. I had seen that. My problem was solved in the end though as in my post above. It was something a bit hicky with PHPMyAdmin. I got it all working in the end with that syntax although I had another way in the documents of doing database inserts but that didn’t seem to work for some reason in the plugin and only this format would.
All fixed now though and I am truly on my way with all of this now!! Hope to have something for people to play around with tomorrow!! 😊
Best wishes,
Mark
Hi Erin,
Tomorrow comes early!! Gosh my watch must be broken!! 😊 😊
Hope you find it useful.
Best wishes,
Mark
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.