ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Making a DB query using PHP in a template

July 13, 2009 12:18pm

Subscribe [1]
  • #1 / Jul 13, 2009 12:18pm

    newvibes

    28 posts

    I know you can use the query module and the query tag in the template, but I don’t want to do that. Is there any global variable that I can use to access the current database connection to make a query? I need to unserialize some data and I can’t do it the way the documentation suggest.

  • #2 / Jul 13, 2009 12:21pm

    ender

    1644 posts

    <?php
    global $DB;
    $data = $DB->query("SELECT something FROM somewhere");
    ?>
  • #3 / Jul 13, 2009 12:22pm

    Ingmar

    29245 posts

    You can always use the Database class directly, of course.

  • #4 / Jul 13, 2009 12:24pm

    newvibes

    28 posts

    I was using the DB class but was throwing errors, then realised I didn’t enable PHP for that template. Annoying.

    Thanks guys!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases