Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

creating a plugin, how to connect to the database

YohnYohn New
edited March 2012 in Vanilla 2.0 - 2.8

Hey guys! this is my first post on vanilla forums since everythings changed.. Ive been a fan for about 6 years now and I wanted to start a site using the forums.

I'm working on a plugin that would allow me to edit pages - about and contact pages.
I created a database table for these 2 other pages, and I'm trying to edit them within the dashboard. i got the link to show up on the side, wrote all the script out (its varly small) and then when I went to try it, I found out I had to use the database classes..
I've been reading the docs -- http://vanillaforums.org/docs/database and I thought it would be easy to do by simply do the
$database = new Database;
but then its saying the database class isnt found.. I'm trying to call the class on a separate page within the dashboard.. can someone help me out? this is what I wrote out before I realized I needed to use the class..

$doIt = mysql_query("SELECT * FROM 'gdn_ExtraPages' WHERE id = '".mysql_real_escape_string($_POST['whichPage'])."' LIMIT 1") or die(mysql_error());
$gotIt = mysql_fetch_array($doIt);
mysql_free_result($doIt);

and $gotIt returns nothing..

If you could tell me what I need to do before that and how to get what I need from the database that would be awesome.. I'm almost thinking I need to create this within a class but not sure.. I'm gonna try that next..

Best Answer

  • ToddTodd Chief Product Officer Vanilla Staff
    Answer ✓

    You are getting the correct result there. Our Gdn_DataSet is a wrapper to deal with data from the database.

    If you call $get->ResultArray() then you'll get an array of the actual data that should be asier for you to parse.

Answers

  • I tried adding it to my class for this plugin like so

    public function grabEP($id){
    $grabIt = Gdn::SQL()->Select('*')->From('ExtraPages')->Where('id', $id)->Get();
    return $grabIt;
    }

    called it like so..

    $haha = $EPClass = new ExtraPagesPlugin;
    $get = $haha->grabEP($_POST['whichPage']);
    print_r($get);

    and then got..

    Gdn_DataSet Object
    (
    [Connection] => PDO Object
    (
    )

    [_Cursor:Gdn_DataSet:private] => -1
    [_DatasetType:protected] => object
    [_EOF:protected] => 
    [_PDOStatement:Gdn_DataSet:private] => PDOStatement Object
        (
            [queryString] => select *
    

    from GDN_ExtraPages ExtraPages
    where id = :id
    )

    [_Result:protected] => 
    

    )

  • ToddTodd Chief Product Officer Vanilla Staff
    Answer ✓

    You are getting the correct result there. Our Gdn_DataSet is a wrapper to deal with data from the database.

    If you call $get->ResultArray() then you'll get an array of the actual data that should be asier for you to parse.

  • my friend wanted the website up fast and all I had left to do was a picture gallery page, so I ended up using text files to store the information.. I'm going to try to edit it up so it works with vanilla better and then submit it to the plugin directory.. :) thanks for the info!

Sign In or Register to comment.