I've installed sorcerer in Joomla! 3.2 to execute some custom php.
The basic php code works fine, but the SQL-query gives no result. My code:
{source}
$servername = //my db-server;
$dbname = //my db-name;
$username = my db-username;
$password = my db-password;
$connection = mysql_connect($servername, $username, $password);
mysql_select_db($dbname);
$abfrage = "SELECT * FROM workshops";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis)) {
echo $row->id;
}
{/source}
At a normal website without joomla! that code works perfect.
edit:
the correct query would look like this:
{source}
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('id', 'workshop_title', 'workshop_time');
$query->from($db->quoteName('workshops'));
$query->order('ordering ASC');
$db->setQuery($query);
$results = $db->loadObjectList();
echo $results->id;
{/source}
Joomla has a class for that, read more about it at with really nice examples on how to set it up http://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase