php - PHP MYSQL SELECT 查询参数包含一个 & 符号
问题描述
我正在使用 PHP PDO 准备好的语句。我传入一个字符串并从 MYSQL 返回记录。我将三个变量传递给该方法。
查询不返回任何内容。如果我在 phpmyadmin 中执行相同的查询,它会返回所有正确的数据。我相信它是 $team 变量中的 & 符号,但是,不知道我要解决它。我没有使用链接,它不是表单元素。这是对该方法的直接调用。三个参数的值是
$season = '2018-19';
$league = 20;
$team = "Texas A&M University-Kingsville";
这是我的方法:
public static function getTeamGames($season, $league, $team){
$conn = parent::connect();
$sql = "SELECT * FROM rfw_games WHERE season = :season &&
league = :league && home = :team";
try {
$st = $conn->prepare( $sql );
$st->bindValue( ":season", $season, PDO::PARAM_STR );
$st->bindValue( ":team", $team, PDO::PARAM_STR );
$st->bindValue( ":league", $league, PDO::PARAM_INT );
$st->execute();
$games = array();
foreach ( $st->fetchAll() as $row ) {
$games[] = new Game( $row );
}
parent::disconnect( $conn);
return $games;
} catch (PDOException $e ) {
parent::disconnect( $conn );
die( "Query failed: " . $e->getMessage() );
}
}
$weeklyGames = Game::getTeamGames( $season, $league, $tName );
我真的很感谢大家的帮助。
先感谢您。
解决方案
我能够解决这个问题。
我不得不在 $team 参数上使用 html_entity_decode。
我将方法更改为以下内容:
public static function getTeamGames($season, $league, $team){
$dTeam = html_entity_decode($team);
$conn = parent::connect();
$sql = "SELECT * FROM rfw_games WHERE season = :season && league = :league && home = :team";
try {
$st = $conn->prepare( $sql );
$st->bindValue( ":season", $season, PDO::PARAM_STR );
$st->bindValue( ":team", $dTeam, PDO::PARAM_STR );
$st->bindValue( ":league", $league, PDO::PARAM_INT );
$st->execute();
$games = array();
foreach ( $st->fetchAll() as $row ) {
$games[] = new Game( $row );
}
parent::disconnect( $conn);
return $games;
} catch (PDOException $e ) {
parent::disconnect( $conn );
die( "Query failed: " . $e->getMessage() );
}
}
推荐阅读
- python - 通过python从旋转的PDF中提取文本
- python - 无法在 tkinter python 中使用循环和字典创建检查按钮?
- azure-devops - 将 Cypress 测试集成到 Azure Devops 拉取请求中
- python - 创建一个引用其值的 Pandas 列
- java - reactx 中的 NoSuchElementException 异常处理
- r - 如何将 R 中的 Sys.Date 从 UTC 转换为 GMT
- c++ - 为什么我从 4 中减去 19 得到的返回值为 1
- python - 在python中共享一个文件夹?
- c# - c# 使用不正确的时区格式解析日期
- firebase - 在 Flutter Web 中使用基于构建模式的生产或开发 Firebase 应用程序