我遇到了问题,下面的代码没有给我任何结果。但是,如果我取消注释指示的行,并注释掉 bind_param 行它可以工作,但这不是违背 mysqli 的目的吗?我的 var_dump 给我的字符串(1)“1”
function teams($mysqli, $league_id) {
echo 'league id = ' . var_dump($league_id);
$sql = "SELECT team_id, team_name FROM teams where league_id='?'";
// $sql = "SELECT team_id, team_name FROM teams where league_id='".$league_id."'";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('i', $league_id);
$stmt->execute();
$stmt->bind_result($col1, $col2);
while($stmt->fetch()) {
$results[] = array(
'team_id' => $col1,
'team_name' => $col2
);
}
$stmt->close();
var_dump($results);
return $results;
}