Need help with database connection MySQL

Totally new to Yii, just installed it this AM on a Ubuntu Server.

This is the first time I ever use a framework but not PHP.

I have this:




/var/www/html/install/latest/apps/common/framework/cli/views/web

app/protected/config$



and within there I have




-rw-rw-r-- 1 dvuser www-data  622 Sep  5 22:58 console.php

-rw-rw-r-- 1 dvuser www-data  238 Oct 26 23:16 database.php

-rw-rw-r-- 1 dvuser www-data 1990 Oct 26 23:15 main.php

-rw-rw-r-- 1 dvuser dvuser 606 Oct 26 23:15 OLDdatabase.php

-rw-rw-r-- 1 dvuser www-data  331 Sep  5 22:58 test.php



I have edited database.php to this




// This is the database connection configuration.

return array(

        'connectionString' => 'mysql:host=localhost;dbname=mwizzema',

        'emulatePrepare' => true,

        'username' => 'dvuser',

        'password' => 'PickPickles',

        'charset' => 'utf8',


);



I ran the requirement checker and all passes but the postgres db and I figure it does not matter since I do not use it.

I am trying to play around with mailwizz ema (future prospective work) as I see an opportunity for work maintaining it. mailwizz ema uses Yii and so, here I am.

Following the guide to install mailwizz ema, I get the above mentioned error. It obviously points to DB connection error so I have

(1) Checked and made sure MySQL is working

(2) Checked and made sure user|password are correct

(3) Checked and made sure database mwizzema exists

I cannot, for the life of me, pin point the source code where the error is triggered nor the root cause of the error since it is very vague.

Can anyone please offer some advise that may help me get pass this hurdle!?!

thank you all in advance for your assistance.

Have you configured the "db" component in your main.php file to point to (or should I say include) the database.php file?

That’s just it, I do not even know which file to edit. I edited the database.php script as shown above but cannot trace any reference to connectionString any where else or where it is being set.

Can you offer some direction as to where is this db component meant to be found?

Thanks!

protected/config/main.php:




return array(

	...

	'components'=>array(

        	...

        	'db'=>require('database.php'),

        	...

	),

	....

);



It would help knowing in details the error. But any way try to check the php server configuration cause of the libs. Even with all passes OK. If you can please send us the error to help you better.

Good luck bro

OK, I’m back to this project - had some issues that needed undivided attention and was forced to divert.

Here is the error I get from the debug trace




04:16:42.798461 	error 	exception.CDbException 	


exception 'CDbException' with message 'CDbConnection failed to open the DB

connection: invalid data source name' in

/var/www/html/install/latest/apps/common/framework/db/CDbConnection.php:399

Stack trace:

#0

/var/www/html/install/latest/apps/common/framework/db/CDbConnection.php(347):

CDbConnection->open()

#1

/var/www/html/install/latest/apps/common/framework/db/CDbConnection.php(325):

CDbConnection->setActive(true)

#2

/var/www/html/install/latest/apps/common/framework/base/CModule.php(394):

CDbConnection->init()

#3

/var/www/html/install/latest/apps/common/framework/base/CModule.php(103):

CModule->getComponent('db')

#4

/var/www/html/install/latest/apps/common/components/managers/OptionsManager.php(164):

CModule->__get('db')

#5

/var/www/html/install/latest/apps/common/components/managers/OptionsManager.php(73):

OptionsManager->loadCategory('system.common.s...')

#6

/var/www/html/install/latest/apps/common/components/init/SystemInit.php(50):

OptionsManager->get('system.common.s...')

#7

/var/www/html/install/latest/apps/common/framework/base/CComponent.php(561):

SystemInit->_runOnBeginRequest(Object(CEvent))

#8

/var/www/html/install/latest/apps/common/framework/base/CApplication.php(211):

CComponent->raiseEvent('onBeginRequest', Object(CEvent))

#9

/var/www/html/install/latest/apps/common/framework/base/CApplication.php(182):

CApplication->onBeginRequest(Object(CEvent))

#10 /var/www/html/install/latest/apps/init.php(219): CApplication->run()

#11 /var/www/html/install/latest/index.php(23):

require_once('/var/www/html/i...')

#12 {main}

REQUEST_URI=/install/latest/

HTTP_REFERER=http://10.0.0.55/install/

---



I checked /var/log/mysql.log in hope I’ll find a more direct reference as to what is causing it to fail or at least the name of the database it is attempting to open but the log file is empty.

Can you from the above tell what am I missing?

I added a couple of Yii::trace() calls and it appears that DB_CONNECTION_STRING is not set thus reference to this constant is not valid or simply taken as a literal string




Yii::trace('connectionString Set To',$this->connectionString);


prints


05:05:08.897016 	trace 	{DB_CONNECTION_STRING} 	


connectionString Set To




I did a global search of DB_CONNECTION_STRING and no where it is defined. Hope this piece of info helps further identify my root cause …

Thanks,

These error logs tell us nothing new.

You need to show us your main.php configuration file (you can remove or censor out the sensitive information).

The path:

/var/www/html/install/latest/apps/common/framework/cli/views/webapp/protected/config

The directory list

total 20

-rw-rw-r-- 1 dvuser www-data 622 Sep 5 22:58 console.php

-rw-rw-r-- 1 dvuser www-data 238 Nov 2 00:05 database.php

-rw-rw-r-- 1 dvuser www-data 1990 Oct 26 23:15 main.php

-rw-rw-r-- 1 dvuser dvuser 606 Oct 26 23:15 OLDdatabase.php

-rw-rw-r-- 1 dvuser www-data 331 Sep 5 22:58 test.php

main.php




... snip ...

                // database settings are configured in database.php

                'db'=>require(dirname(__FILE__).'/database.php'),

... snip ...



database.php




<?php


// This is the database connection configuration.

return array(

        'connectionString' => 'mysql:host=localhost;dbname=mwizzema',

        'emulatePrepare' => true,

        'username' => 'dvuser',

        'password' => 'PickPickles',

        'charset' => 'utf8',


);



The database exists - I can connect to it with above credentials.

I’ve tried 10.0.0.55 in lieu of localhost and nothing.

OK - I have decided to simply plug in the dsn or connection string directly where constants were used - I am sure this is not the recommended way but need to move on …

scares me that setting up a database name is this complicated - I have not even gotten started with what I expect to be real development.

Knowing the "right" way to do it and actually see it work would be a great milestone. Thanks!

I can see no errors in your configuration files.

It might not be a Yii problem, sorry.

Is your MySQL server running on default port?