joomla/joomla-platform

config.example.php list db but libraries/database/driver/mysql.php needs options[database] to work

IberoMedia opened this issue · 3 comments

Hello,

File libraries/database/driver/mysql.php requires that the database object include an option indexed as 'database.' I was using a config.php file based on the config.example.php that is included in the platform's downloadable package from http://api.joomla.org/. File config.example.php includes variable $db, which I presumed was the only variable I needed to declare the target database. I struggled to figure out why I was unable to make successful queries with my application's database class, a child class of JDatabaseDriverMysql.

After trailing backwards, I figured that although I was connecting to the server, I was not selecting a database. When I echoed mysql_error() I got "No database selected" and thus I knew what to look for.

The issue is that config.example.php should include variable public $database = 'user_database';

I do not know wehter public $db = 'user_database'; should be kept, but the existence of this variable led me to believe I needed no further tweaking for a JConfig object from this file.

The file libraries/database/driver/mysql.php looks for options[database]

    // If auto-select is enabled select the given database.
    if ($this->options['select'] && !empty($this->options['database']))
    {
        $this->select($this->options['database']);
    }

and this leads me to suggest that config.example.php represent what this file needs to work correctly. Otherwise, then the code should look for options['db']

I agree, but if you look at the JFactory::getDbo() method here https://github.com/joomla/joomla-platform/blob/12.1/libraries/joomla/factory.php#L589 you'll see that this is accounted for in the creation of the database object. While it would be convenient, it may break existing tutorials that instruct users how to implement the database classes in their application. So, I think we should leave it as is, but potentially add something to the docs to make it clear.

Hello,
I can't find /database/ folder in my platform root!
any help?

I would download the package for your Joomla version, extract folders, and copy the database folder to your existing Joomla. I suggest you back up your existing copy before doing this. It is strange you cannot find it. I wonder how is your existing Joomla installation even working