我一直在使用准备好的语句做一些工作,因为它们更安全,但是在以前版本的 sql 数组获取 ($query->fetch_array(MYSQL_ASSOC)) 中,它不允许从数组中返回一项。
function getForumInfo( $id, $col ){
global $mysqli, $db_table_prefix;
$stmt = $mysqli->prepare("SELECT ? FROM forums WHERE id = ?");
$stmt->bind_param("si", $col, $id);
$stmt->execute();
$stmt->bind_result($val);
$out = $stmt->fetch()[$val];
$stmt->close();
return $out;
}
关于那件事只是看起来不太好。
如果我要执行以下操作:
echo getForumInfo( 7, 'name');
它会只返回列名中的值,其中 id = 7?