如何使用Zend Framework的Zend_Db_Select
创建此查询SELECT movie.*, count(DISTINCT similar.tag) as shared_tags FROM movie INNER JOIN
( tagged AS this_movie INNER JOIN tagged AS similar USING (tag) )
ON similar.movie = movie.id
WHERE this_movie.movie=<current_movie_id>
AND movie.id != this_movie.movie
GROUP BY movie.id
ORDER BY shared_tags DESC
答案 0 :(得分:0)
$query = ("SELECT movie.*, count(DISTINCT similar.tag) as shared_tags
FROM movie
INNER JOIN (tagged AS this_movie
INNER JOIN tagged AS similar USING (tag) )
ON similar.movie = movie.id
WHERE this_movie.movie=<current_movie_id>
AND movie.id != this_movie.movie
GROUP BY movie.id ORDER BY shared_tags DESC ");
mysql_query('$query') or die(mysql_error());
如果您在查询中使用任何参数,请不要忘记使用
来逃避所有参数$param = mysql_real_escape_string($param);
在将它们提供给sql_query之前,你会被SQL注入攻击所困扰。