php – 带有IN子句的MySQL PDO

前端之家收集整理的这篇文章主要介绍了php – 带有IN子句的MySQL PDO前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在将我的所有查询切换为PDO格式,而我特别遇到涉及IN()子句的问题.

$nba[0] = "Boston Celtics";
$nba[1] = "New York Knicks";
$nba[2] = "Houston Rockets";

$query = "SELECT game_id
        FROM table
        WHERE date_int >= :date_int 
        AND (home_team = :team OR away_team = :team) 
        AND home_team IN(:list)
        AND away_team IN(:list)
        ORDER BY game_date_int ASC 
        LIMIT 1";               
$stmt = $db->prepare($query);
$stmt->execute(array(':date_int' => $limit,':team' => $team,':list' => implode(',',$nba)));
最佳答案
你可以像这样解决这个问题:

$nba = array();
$nba[0] = "Boston Celtics";
$nba[1] = "New York Knicks";
$nba[2] = "Houston Rockets";

$params = array(':date_int' => $limit,':team' => $team);
$nba_teams = array();
for($i=0;$i

尚未测试过,但我想你知道我在尝试什么

猜你在找的MySQL相关文章