We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How do I create a table for use in my extension?

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

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

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

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

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

I presume you have seen this?

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

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

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Can you post your solution so that I can find it when I need to do this?

thanks

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hi Erin,

I will be uploading this to a forum post (hopefully) some time tomorrow. You can then open it up and take it apart as much as you like.

Will let you know when it is done! 😊

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hi Erin,

Tomorrow comes early!! Gosh my watch must be broken!! 😊 😊

Hope you find it useful.

Best wishes,

Mark

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.