我正在使用http://www.yiiframework.com/doc/guide/1.1/en/database.dao
数据访问对象 (DAO) 使用 PDO。
不确定哪个最好
选项一 - 内联代码
$alias_name =Utils::checkEnteredData($alias_name);
$connection = Yii::app()->db;
$sql_images = $connection->createCommand("SELECT ig.id,
ig.is_flickr,
ig.main_image,
ig.author_id,
ig.description,
ig.latitude,
ig.longitude,
ig.is_youtube,
ig.author_id,
ig.flickr_youtube_id,
ig.thumbnail_image_medium,
ig.thumbnail_image,
ig.alias_title,
ig.image_hits,
ig.title,
ig.created_on,
a.title,
a.alias_title as album_alias_title,
igo.realname,
igo.username,
igo.location from image_gallery ig
JOIN album a ON ig.album_id = a.id
LEFT JOIN image_gallery_owner igo ON ig.author_id = igo.id
WHERE ig.approved =:approved AND ig.visible=:visible AND ig.alias_title =:alias_title LIMIT 1");
$sql_images->bindValues(array(':alias_title'=>$alias_name, ':approved'=>'Yes', ':visible'=>'1'));
$image = $sql_images->queryAll();
选项 2 存储过程:
public function getImageFromAliasTitle($alias_title)
{
$alias_title =Utils::checkEnteredData($alias_title);
$connection = Yii::app()->db;
$command = $connection->createCommand("CALL getSingleImage(:alias_title)");
$command->bindParam(":alias_title",$alias_title,PDO::PARAM_STR);
$image = $command->queryAll();
return $image;
}