Yii Framework Forum: 关于自动连接数据库 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

关于自动连接数据库 关于自动连接数据库,为什么比自行new一个CDbConnection要慢很多? Rate Topic: -----

#1 User is offline   Aros 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 20-March 13

Posted 27 March 2013 - 03:00 AM

关于自动连接数据库,为什么比自行new一个CDbConnection要慢很多?

//手动连接数据库
$conn = new CDbConnection('mysql:host=127.0.0.1;dbname=test', 'root', 'password');
$conn->enableParamLogging = 1;
$conn->tablePrefix = 'tbl_';

//以Yii::app()这种方式获取conn就会很慢,不知道是什么原因?
//$conn = Yii::app()->db;

$command = $conn->createCommand('SELECT * FROM `tbl_main`');
$data = $command->queryRow();

$this->render('index');
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users