Skip to main content
added 9 characters in body
Source Link
saibbyweb
  • 2.3k
  • 4
  • 23
  • 50

How can I make few global php functions which can be called from any Joomla custom module? E.g I wish to make a global function executing a select database query:

function select($row,$table_name,$where,$equals) {

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($row)
      ->from($db->quoteName($table_name))
      ->where($db->quoteName($where) . "=" . $db->q($equals));
$db->setQuery($query);
$result = $db->loadResult();
$row = $db->loadAssoc();
return $row[$row];

}

and then call it from any module:

$result = select('id','#__table','name','john');

what would be the best way to achieve this?

How can I make few global php functions which can be called from any Joomla custom module? E.g I wish to make a global function executing a select database query:

select($row,$table_name,$where,$equals) {

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($row)
      ->from($db->quoteName($table_name))
      ->where($db->quoteName($where) . "=" . $db->q($equals));
$db->setQuery($query);
$result = $db->loadResult();
$row = $db->loadAssoc();
return $row[$row];

}

and then call it from any module:

$result = select('id','#__table','name','john');

what would be the best way to achieve this?

How can I make few global php functions which can be called from any Joomla custom module? E.g I wish to make a global function executing a select database query:

function select($row,$table_name,$where,$equals) {

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($row)
      ->from($db->quoteName($table_name))
      ->where($db->quoteName($where) . "=" . $db->q($equals));
$db->setQuery($query);
$result = $db->loadResult();
$row = $db->loadAssoc();
return $row[$row];

}

and then call it from any module:

$result = select('id','#__table','name','john');

what would be the best way to achieve this?

Source Link
saibbyweb
  • 2.3k
  • 4
  • 23
  • 50

Global PHP functions?

How can I make few global php functions which can be called from any Joomla custom module? E.g I wish to make a global function executing a select database query:

select($row,$table_name,$where,$equals) {

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($row)
      ->from($db->quoteName($table_name))
      ->where($db->quoteName($where) . "=" . $db->q($equals));
$db->setQuery($query);
$result = $db->loadResult();
$row = $db->loadAssoc();
return $row[$row];

}

and then call it from any module:

$result = select('id','#__table','name','john');

what would be the best way to achieve this?