1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Accessing database

Discussion in 'Community' started by jh, May 16, 2019 at 2:59 PM.

  1. jh

    jh Member

    Level: Community
    Hi

    I wanted to try and create a custom module which containted some text and data from my fabrik databases. I have tried to do this with Sourcerer but I can not seem to get it to return anything. I have tried code along the lines of:

    {source}<?php
    $query = $db->getQuery(true)
    ->select($db->quoteName('factory'))
    ->from('object_table')
    ->where($db->quoteName('id').' = '.$db->quote('3'));

    $db->setQuery($query);
    $result = $database->loadResult();

    return $result;
    ?>{/source}

    but nothing is being returned.

    Have I missed something or is it not possible to return data this way?

    Many thanks
     
  2. startpoint

    startpoint Active Member

    Level: Community
    PHP:
    {source}<?php
    $db = JFactory::getDbo();
    $query = $db->getQuery(true)
    ->select($db->quoteName('factory'))
    ->from('object_table')
    ->where($db->quoteName('id').' = '.$db->quote('3'));

    $db->setQuery($query);
    $result = $database->loadResult();

    return $result;
    ?>{/source}
     
  3. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Why 'return'?

    If that code is in a custom module, there's nothing to return to. You need to echo the response, not return it. When J! runs custom modules, it captures the output buffer.

    -- hugh
     
  4. jh

    jh Member

    Level: Community
    Perfect, thank you for your help.
     

Share This Page