1

I am pretty new to Joomla, and I'm stuck!

I'm trying to access the Joomla DB from a PHP script, using the JFactory::getDBO(); method. I noticed all my queries were returning '0' results, even though the SQL looks fine.

I then noticed that

$db = JFactory::getDBO();
echo "Database prefix is : " . $db->getPrefix();

Outputs:

"Database prefix is : jos_". 

My DB Prefix should be - "wvfd_".

This is the part of code that initializes joomla:

    define( '_JEXEC', 1 );

    define( 'DS', DIRECTORY_SEPARATOR );

    define( 'JPATH_BASE', realpath(dirname(__FILE__).DS.'..' ));


    require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
    require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

    $mainframe =&JFactory::getApplication('site');

I have checked in the Joomla backend, and the prefix is set correctly. I have checked configuration.php, and it is set correctly in there too?

Why is $db = JFactory::getDBO(); connecting me to a DB that does not exist?

All/Any help appreciated, thanks!

  • Do you have multiple installations of Joomla running in different directories? If so, be sure that your JPATH_BASE is defined correctly and pointing to the correct directory as you have have a different prefix on different installations – Lodder Sep 17 '15 at 11:21
1

To get your db prefix, you need to create object of Jconfig class(configuration file). Let us suppose you are creating a file connectivity.php and place it root. And the code in that file would be :

require_once ('configuration.php' );

    $var_cls = new JConfig();
    $connlink = mysql_connect($var_cls->host, $var_cls->user, $var_cls->password) or die("Connection Failure to Database");
    mysql_select_db($var_cls->db, $connlink);

 return $db_prefix = $var_cls->dbprefix;

$db_prefix will give you the correct prefix of your db.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.