Connecting Joomla to database
- July 1st, 2008
- Posted in Joomla
- Write comment
preparing the query
// Get a database object $db = JFactory::getDBO(); $query = "SELECT * FROM #__example_table WHERE id = 999999"; $db->setQuery($query);
of course using the Database
Basic Query Execution
- query (This should be user after Set Query if you want to use getNumRows)
Query Execution Information
- getAffectedRows
-explain
-insertidInsert Query Execution
-insertObject
Single Value Result
-loadResult
Single Row Results
-loadObject
-loadRow
-loadResultArray
Multi-Row Results
-loadObjectList
-loadRowList
-loadAssocList
Misc Result Set Methods
-getNumRows
a nice code would go like
$database = JFactory::getDBO();
$user_name=$_POST['username'];
$query = "SELECT * FROM #__users";
$database->setQuery($query);
$existing_users=$database->loadResultArray();
if (in_array($user_name, $existing_users)) {.. do something }
Thanks clean n clear code