开发者

How to connect the Db and get the data from table in Joomla php

开发者 https://www.devze.com 2022-12-17 20:53 出处:网络
I want to connect the Joomla DB and i have created table in PHPmyAdmin. And want to get the row and val开发者_如何学Pythonues from the field.Best way when having a proper JTable:

I want to connect the Joomla DB and i have created table in PHPmyAdmin. And want to get the row and val开发者_如何学Pythonues from the field.


Best way when having a proper JTable:

$row =& JTable::getInstance('my_table', '');
$row->load($id); 

When working without JTable:

$db = &JFactory::getDbo();  
$sql = 'SELECT * FROM #__table WHERE id ='.$id;
$db->setQuery($sql);
$object = $db->loadObject(); 

OFC you can make that more elegant inside MVC. BUT for starters maybe enough.


$db = JFactory::getDBO();

$query = "select id,title from #__content";

$db->setQuery($query);

$result = $db->loadObjectList();//here we got array of stdClass===prepared objects in PHP 5.3

foreach($result as $res){
  echo $res->id."".$res->title;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消