手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2012年03月7日的文章

Yii Framework DB 中的一些参数

Yii的AR一直在被使用,当然,偶尔也只是看看其中的参数,都是直接把main.php中的数据注释掉就完事了
但事实上我们都忽略了一点点现实,那就是默认参数是没有什么性能提升的。

1、'schemaCachingDuration'=>3600,
这个在默认参数中是不存在的,如果你的表结构不太变动,完全可以不需要每次都show columns,show create table之类的。加上这个参数,可以将表结构缓存一小时(嗯,前提是,你配置了cache组件)

2、emulatePrepare=true ,这个是默认里面就带有的,它有什么用呢?
官方是这样说的:whether to turn on prepare emulation. Defaults to false, meaning PDO will use the native prepare support if available. For some databases (such as MySQL), this may need to be set true so that PDO can emulate the prepare support to bypass the buggy native prepare support. Note, this property is only effective for PHP 5.1.3 or above.
好吧,为了以防万一,还是打开算了

3、'enableProfiling'=>true
如果你想优化代码的话,可以尝试设置为true看看。官方在guide里说:By setting CDbConnection::enableProfiling to be true in the application configuration, every SQL statement being executed will be profiled. The results can be readily displayed using the aforementioned CProfileLogRoute, which can show us how much time is spent in executing what SQL statement. We can also call CDbConnection::getStats() to retrieve the total number SQL statements executed and their total execution time.

4、 'enableParamLogging'=>true,
这个就相对比较简单了,如果你设置为True,你在log中,就可以看到你的每次参数的参数是什么了,而不是:y01:y02这样的顺序变量。

5、tablePrefix = "xxx",这没什么好解释的。。。

6、charset="xxx" ,也没有什么好解释的,utf-8的话,中间的减号不要。。


这些都是常用的。。所以列出来

Tags: yii