system.db.CDbConnection taking more than 1 second to execute in yii

I am a new to yii although i have worked a lot with codeigniter and was just trying to convert my code from codeigniter to yii But the CDbconnection is taking more than 1 second to execute i have attached a screenshot. also the sql code i am using.

$criteria = new CDbCriteria();

$criteria->select = "total_photos";

$data = array( ‘Gallerys’ => Gallerynames::model()->findAll($criteria));

I have attached the logger screenshot.

As a helper, that image is here:

It looks a lot like either CDbConnection or your MySQL server is misconfigured. In any way, it shouldn’t take that long to open a database connection. Are other applications that slow as well on your system? If so, the might be an error in your network stack.

Also: It looks like you just want to fetch the number of photos in a gallery. Your approach for that is a bit of an overkill: Use STAT-relations for that.

No i have implemented the same thing in codeigniter it takes around 0.04 secs.

Here is my db config.


'db'=>array(

			'class' => 'system.db.CDbConnection',

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

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',

			'enableProfiling' => true,

			'schemaCachingDuration' => 3600,

		),



Care to c&p the relevant sections of your application’s config? Also: Is your CI app connecting through PDO? It is my understanding that this isn’t strictly necessary.

No the codeigniter app is not using PDO.

please look in the config i have posted above.

Heh, brilliant. You edited your post after I sent mine, haven’t you? ;)

Well, there’s nothing striking me as particularly odd. Could be a deficiency of PDO, in which case I’d be unable to help you any further. You mgiht be well advised to open a ticket on the PHP bugtracker.

By any chance: Have you configure a cache component?

Try


'connectionString' => 'mysql:host=127.0.0.1;dbname=yiiwiki',

Ya this worked out actually this was not a yii problem it was due to pdo.

reasons:- on putting localhost it first tries to connect via ipv6 and then falls back to ipv4 while putting directly 127.0.0.1 it dosen’t do this refrence:- drupal blog.

Thanks for the solution. I think that’s a common problem. I’d like to see it mentioned on The Guide:DAO since that’s the first step for everyone who wants to connect to his database. I’d like to post a comment there, but I’m not allowed to do so.