Joomla component Mysql

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
BirdieUK
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun Sep 23, 2007 2:22 pm

Joomla component Mysql

Post by BirdieUK » Sun Sep 23, 2007 2:28 pm

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.

User avatar
tjay
Joomla! Intern
Joomla! Intern
Posts: 73
Joined: Thu Aug 18, 2005 1:50 am
Location: New Orleans
Contact:

Re: Joomla component Mysql

Post by tjay » Sun Sep 23, 2007 5:50 pm

Do you have the proper includes in place?
Can you be more specific on what you mean by dont work?
This day it is my wish that I helped you to live

BirdieUK
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun Sep 23, 2007 2:22 pm

Re: Joomla component Mysql

Post by BirdieUK » Sun Sep 23, 2007 6:49 pm

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.

User avatar
ianmac
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 237
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: Joomla component Mysql

Post by ianmac » Sun Sep 23, 2007 7:38 pm

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
Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!

BirdieUK
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun Sep 23, 2007 2:22 pm

Re: Joomla component Mysql

Post by BirdieUK » Sun Sep 23, 2007 9:48 pm

Ooh ok.

Thanks  :).


Post Reply