database connection problem

Discussion in 'Website Development & Design' started by sudhakar1, Oct 14, 2013.

  1. sudhakar1

    sudhakar1
    uix_expand uix_collapse
    Member

    Joined:
    Sep 9, 2013
    Messages:
    150
    Likes Received:
    6
    How to connect the database in joomla 2.5? what are the steps follow? can one give details and example?
     
  2. sahilpatel

    sahilpatel
    uix_expand uix_collapse
    New Member

    Joined:
    Sep 16, 2013
    Messages:
    16
    Likes Received:
    2
    Connecting to the database is done using the code below:

    $db = JFactory::getDbo();

    To get results from a database table using Joomla 2.5 standards, you can try something like this:

    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query->select('category_id')
    ->from('#__easyblog_post')
    ->where('post_id = 5');
    $db->setQuery($query);
    $row = $db->loadResult();

    echo $row;

    Note that when defining a Joomla database table, the prefix is defined as #__
     
    • Like Like x 2

Share This Page