0

Below are my code lines

    $db = JFactory::getDbo();
    $query =$db->getQuery(true);
    $query ->select('id')
           ->from($db->quoteName('#_menu'))
           ->where('alias'. "=" ."'about'".'AND published = 1');
    $db->setQuery($query);
    $result = $db->loadObjectList();

how to release db connection after query execution ?

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
user1671308
  • 859
  • 2
  • 8
  • 11
  • What do you mean by "release" the connection? – Lodder Jun 15 '16 at 10:20
  • In Java we have option to close the connection after query executing ,for example in Java http://stackoverflow.com/questions/4507440/must-jdbc-resultsets-and-statements-be-closed-separately-although-the-connection – user1671308 Jun 15 '16 at 10:36

2 Answers2

0

Trying to close the connection in Joomla is pointless because the core and even 3rd party extensions that call JFactory::getDbo(); so it will be reopened.

If you really need to, then you can use $db->disconnect(); which basically calls mysqli_close() or the equivalent to whatever database drive you're using.

Lodder
  • 19,758
  • 10
  • 59
  • 100
0

Although i suppose after each query the database connection gets closed. Still there are two methods that can be used

  1. If you want to close or disconnect the database session, you can use:

    $db->disconnect(); Ref: http://api.joomla.org/cms-3/classes/JDatabaseDriver.html#method_disconnect

  2. You can also use this instead after a query result is passed to a Variable:

    $db->freeResult(); Ref : http://api.joomla.org/cms-3/classes/JDatabaseDriverMysql.html#method_freeResult

Amit Ray
  • 3,445
  • 2
  • 19
  • 35
  • Pretty much a copy and paste of this: http://stackoverflow.com/a/25914199/1362108 – Lodder Jun 15 '16 at 15:41
  • @Lodder Entire stackoverflow answers are a copy paste of some page. php.net site has all the answers of many php questions here. Even walking, eating, drinking is copy paste of what elders did. – Amit Ray Jun 15 '16 at 15:48