connect External database joomla 3.3

480 views
Skip to first unread message

Marcello wpr

unread,
Oct 8, 2014, 6:54:09 PM10/8/14
to joomla-de...@googlegroups.com
Hi,
I am converting my module from joomla 2.5 to joomla 3.3 but I'm having a problem with the connection to an external database, in joomla 2.5 I do:

$option['driver'] = 'mysql';
$option['host'] = 'host';
$option['user'] = 'MyExternalUserDb';
$option['password'] = 'MyExternalPswDb';
$option['database'] = 'MyExternalDatabase';
$option['prefix'] = '';

$db = &JDatabase::getInstance( $option );
$db->setQuery($query);
$results=$db->loadResultArray();

and work all ok in joomla 2.5.

In Joomla 3.3 I use:

$option['driver'] = 'mysql';
$option['host'] = 'host';
$option['user'] = 'MyExternalUserDb';
$option['password'] = 'MyExternalPswDb';
$option['database'] = 'MyExternalDatabase';
$option['prefix'] = '';

$db = JDatabaseDriver::getInstance( $option ); // changed in joomla 3.3
$db->setQuery($query);
$results=$db->loadResultArray();

but does not work, I do not get any error, but doing a print_r($db) after JDatabaseDriver::getInstance I can see that the object is not initialized properly, you have any suggestions on how to successfully connect to an external database in joomla 3.3? Very thanks

ModaCalcio.com - e-reall ebay

unread,
Oct 9, 2014, 3:14:53 AM10/9/14
to joomla-de...@googlegroups.com
Assure that the receiving domain , in which you have the DB permits write from external , usually for safety measure that not happens


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Marcello wpr

unread,
Oct 9, 2014, 4:28:31 AM10/9/14
to joomla-de...@googlegroups.com
Hi gius_barb, thanks for your replay, no it is not a permission problem, the database is on the same database server of joomla, in fact I tried to connect and run queries with the standard php (mysql_query and mysql_connect) and everything works perfectly, is just JDatabaseDriver :: getInstance of Joomla that does not work, a bug in getInstance or has been changed the method of access to external databases in joomla 3.3?

Tuan Pham Ngoc

unread,
Oct 9, 2014, 4:41:36 AM10/9/14
to joomla-de...@googlegroups.com
Hi Marcello 

$db->loadResultArray(); doesn't work in Joomla 3 anymore. You need to use $db->loadColumn(); instead. Maybe that's the reason of the error ?

Dimitris

unread,
Oct 9, 2014, 5:33:04 AM10/9/14
to joomla-de...@googlegroups.com
Try this
JDatabaseDriverMysql::getInstance( $option );

ModaCalcio.com - e-reall ebay

unread,
Oct 9, 2014, 5:50:43 AM10/9/14
to joomla-de...@googlegroups.com
ok the host was not specified . if it's always localhost shouldn't be problem

Thank you

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send email to joomla-de...@googlegroups.com.
Message has been deleted

Marcello wpr

unread,
Oct 9, 2014, 9:19:48 AM10/9/14
to joomla-de...@googlegroups.com
@ Tuan,
it is correct, the problem was $db->loadResultArray(), with $db->loadColumn(); the connection work, very thanks
to you and to all for the help you have given me.

On Thursday, October 9, 2014 10:41:36 AM UTC+2, Tuan Pham Ngoc wrote:
Hi Marcello 

$db->loadResultArray(); doesn't work in Joomla 3 anymore. You need to use $db->loadColumn(); instead. Maybe that's the reason of the error ?

Tuan Pham Ngoc

unread,
Oct 9, 2014, 9:37:44 AM10/9/14
to joomla-de...@googlegroups.com

@Marcello No problem. I'm glad it helps :).
Reply all
Reply to author
Forward
0 new messages