How to get the database prefix value ?

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
User avatar
alainroger
Joomla! Explorer
Joomla! Explorer
Posts: 438
Joined: Sat Apr 25, 2009 4:48 am
Location: France
Contact:

How to get the database prefix value ?

Post by alainroger » Thu Oct 20, 2011 11:02 pm

Hi,

how can i get the database prefix (e.g. jos_ for 1.5 or anything else if user changed it) during component installation ?
thx
Last edited by imanickam on Fri Oct 21, 2011 2:51 am, edited 1 time in total.
Reason: Moved the topic from the forum Extensions to the forum Joomla! Coding
what does not kill you, makes you stronger

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 26686
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: How to get the database prefix value ?

Post by imanickam » Fri Oct 21, 2011 2:47 am

I doubt whether you need to do that as the place holder could be used for the prefix.

Review of the document http://docs.joomla.org/How_to_use_the_d ... our_script could be of help.
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Global Moderators Team | Translations Coordination Team | Tamil (தமிழ்) Translation Team

Eegan - Support the poor and underprivileged

User avatar
radiant_tech
Joomla! Guru
Joomla! Guru
Posts: 531
Joined: Sat Dec 15, 2007 3:02 pm
Location: Washington DC Metro

Re: How to get the database prefix value ?

Post by radiant_tech » Fri Oct 21, 2011 11:58 am

Code: Select all

$app = JFactory::getApplication();
$prefix = $app->getCfg('dbprefix');

tkuschel
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Wed May 30, 2012 2:22 pm
Location: Wien, Austria
Contact:

Re: How to get the database prefix value ?

Post by tkuschel » Wed Mar 09, 2016 10:19 am

With Joomla 3.x and database environment, this is more convenience in that context:

Code: Select all

$db = JFactory::getDbo();
$prefix = $db->getPrefix();
Thomas
PS: In a standard query the place holder #__ is recommended, but sometimes with special mysql processing the prefix is needed.


Locked

Return to “Joomla! 2.5 Coding”