如果我必须连续执行多个查询,这样做是否更好:
$connection = Yii::app()->db;
一次...然后继续使用 $connection,或者如果我有多个这样的功能是否会产生开销:
function mainFunction() {
$dbResult1 = dbresult1();
$dbResult2 = dbresult2();
$dbResult2 = dbresult3();
}
function dbresult1() {
$connection = Yii::app()->db;
// do stuff
return $result;
}
function dbresult2() {
$connection = Yii::app()->db;
// do stuff
return $result;
}
function dbresult3() {
$connection = Yii::app()->db;
// do stuff
return $result;
}
这样做会更好:
function mainFunction() {
$connection = Yii::app()->db;
// do stuff with $connection for $dbResult1
// do stuff with $connection for $dbResult2
// do stuff with $connection for $dbResult3
}
?