LIKE运算符无法正常工作

时间:2015-08-07 10:39:23

标签: php sql sql-like

我正在尝试更新数据库中的某些值,我获取要更新的值的主表具有以下结构:

http://api.football-data.org/alpha/soccerseasons/403/leagueTable 所以在更新查询中我执行以下语句:

UPDATE leaguetable SET matchDay = ?, position = ?, teamName = ?, 
playedGames = ?, points = ?, goals = ?, goalsAgainst = ?, 
goalDifference = ?, self = ?, soccerSeason = ?, team = ? WHERE
self LIKE 'http://api.football-data.org/alpha/soccerseasons/403/leagueTable'"

此查询是正确的,但是当我在PhpMyAdmin的控制台中尝试它时,它会返回0 rows,因为值self具有以下结构:

http://api.football-data.org/alpha/soccerseasons/403/leagueTable/?matchday=2

我在like属性中做错了什么?

注意:我在名为http://api.football-data.org/alpha/soccerseasons/403/leagueTable的变量中传递值$x,在帖子中链接只是一个显示链接布局的示例。

3 个答案:

答案 0 :(得分:4)

尝试使用%(通配符)后:

UPDATE leaguetable SET matchDay = ?, position = ?, teamName = ?, 
        playedGames = ?, points = ?, goals = ?, goalsAgainst = ?, 
        goalDifference = ?, self = ?, soccerSeason = ?, team = ?    WHERE self     LIKE 'http://api.football-data.org/alpha/soccerseasons/403/leagueTable%'

答案 1 :(得分:1)

您必须使用通配符来获取输出

UPDATE leaguetable SET matchDay = ?, position = ?, teamName = ?, 
playedGames = ?, points = ?, goals = ?, goalsAgainst = ?, 
goalDifference = ?, self = ?, soccerSeason = ?, team = ?    WHERE self LIKE 'http://api.football-data.org/alpha/soccerseasons/403/leagueTable%'"

答案 2 :(得分:1)

您需要包含通配符%才能正常工作。

在此处详细了解MSDN LIKE

特别是关于通配符%

'http://api.football-data.org/alpha/soccerseasons/403/leagueTable%'发现所有网址都以给定的开头,包括所需的/?matchday=2

在您的代码中:

UPDATE leaguetable 
SET matchDay = ?, position = ?, teamName = ?, playedGames = ?, points = ?, goals = ?, goalsAgainst = ?, goalDifference = ?, self = ?, soccerSeason = ?, team = ?    
WHERE self LIKE 'http://api.football-data.org/alpha/soccerseasons/403/leagueTable%'