1

I have created new php file in component. I want to get connection to Joomla database but connection unknown. Error message is the following:

Fatal error: Class 'JFactory' not found in D:\www\Joomla1.5\components\com_hello\views\hello\tmpl\index.php on line 13

How do I use JFactory::getDBO() in public ?

SomeKittens
  • 38,868
  • 19
  • 114
  • 143
user777692
  • 21
  • 3
  • 6

2 Answers2

0

Hi in my case $result === null not worked, but !$result - worked good

$db = JFactory::getDBO();
$db->setQuery('INSERT INTO #__table (col1, col2) VALUES (val1, val2)');
$result = $db->query();
if (!$result) {
  JError::raiseWarning(100, $db->getErrorMsg());
}
Lodder
  • 19,758
  • 10
  • 59
  • 100
bunak
  • 1
0

Why are you trying to get a database object in your tmpl? DB objects should only be used in either your controller or model, never in your view or tmpl. Tmpl should contain very little logic code and mostly HTML.

The idea is to get your information needed by calling a function in your model. You then pass this data by reference to your tmpl where you echo it out.

[EDIT]

$db = JFactory::getDBO();
$db->setQuery('INSERT INTO #__table (col1, col2) VALUES (val1, val2)');
$result = $db->query();
if ($result === null) {
  JError::raiseWarning(100, $db->getErrorMsg());
}
Martin
  • 10,294
  • 11
  • 63
  • 83