Page 1 of 1

Joomla component Mysql

Posted: Sun Sep 23, 2007 2:28 pm
by BirdieUK
Hey, i have the newest Joomla installation and its my first time integrating my scripts into Joomla.

1 big problem however is that i cant ever seem to get Mysql working with it.

Seems a bit sudden but i'm just wondering why my component won't work with....

Code: Select all

$sql = 'SELECT * FROM schools';
$database->setQuery( $sql );
$rows = $database->loadObjectList();
foreach ( $rows as $row ) {
echo $row->id;
}


Thanks, i've been attempting this for ages and i bet its obvious.

Re: Joomla component Mysql

Posted: Sun Sep 23, 2007 5:50 pm
by tjay
Do you have the proper includes in place?
Can you be more specific on what you mean by dont work?

Re: Joomla component Mysql

Posted: Sun Sep 23, 2007 6:49 pm
by BirdieUK
Sorry about the briefness of the topic. I have just been trying to figure out how to explain the problem best.

Well, i've found that the page fails to actually display if i use the default methods of starting a database connection like above.

It might be that the variable is being used or the connection is already established. I'm not sure.

Thanks for replying, i'll test out new methods.

Re: Joomla component Mysql

Posted: Sun Sep 23, 2007 7:38 pm
by ianmac

Code: Select all

$sql = 'SELECT * FROM schools';
$database->setQuery( $sql );
$rows = $database->loadObjectList();
foreach ( $rows as $row ) {
echo $row->id;
}


If you are using Joomla! 1.0, then you need to add global $database at the top of your function.

If you are using Joomla! 1.5, then you need to add:
$database =& JFactory::getDBO();  before the code above.

Ian

Re: Joomla component Mysql

Posted: Sun Sep 23, 2007 9:48 pm
by BirdieUK
Ooh ok.

Thanks  :).