带参数的PHP MySQL查询由于参数而返回语法错误


PHP MySQL query with parameters returns sytax error because of the parameters

我有以下php代码:

$id=1;
    $query = 'select id from role_perm where perm_id = :id';
    if($statement =$GLOBALS["DB"]->prepare($query)){
    $result =& $statement->execute(array(':id' => $id));
    $t = $result->fetch_all();

但是当我尝试运行这段代码时,我得到一个错误:

1064你的SQL语法错误;查看手册对应于MySQL服务器版本,以便使用正确的语法第1行:id

我在网上看了很多问题和信息,试图把我的陈述以不同的方式,但我总是以这样的错误告终,我试过吗?参数也是如此。如何让它识别参数?我的数据库配置:

$databaseConnection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($databaseConnection->connect_error)
{
    die("Database selection failed: " . $databaseConnection->connect_error);
}
// Create tables if needed.
prep_DB_content();
$GLOBALS['DB'] = $databaseConnection ;
$query = 'select id from role_perm where perm_id = ?';
if($statement = $GLOBALS["DB"]->prepare($query)){
   $statement->bind_param("i", $id);
   $statement->execute();
   $statement->store_result();
   $statement->bind_result($id_result);
   while ($statement->fetch()) {
       // code here
   }
   $statement->close();
}