如何将mysql_fetch_assoc更改为mysqli

时间:2015-01-10 13:11:16

标签: mysql mysqli

如何将其更改为mysqli?

// add meta_key to the query
$get_user_data = mysql_query("SELECT `meta_value`,`meta_key` FROM `table` WHERE `user_id` = $user_id", $link);

// use _assoc instead of _array, we do not need the numerical indexes.
while($row=mysql_fetch_assoc($get_user_data)){
  $userdata[$row['meta_key']] = $row['meta_value'];
}

1 个答案:

答案 0 :(得分:0)

您只需在代码中进行简单的更改:

// add meta_key to the query
$get_user_data = mysqli_query($link,"SELECT `meta_value`,`meta_key` FROM `table` WHERE `user_id` = $user_id");

// use _assoc instead of _array, we don't need the numerical indexes.
while($row=mysqli_fetch_assoc($get_user_data))
{
     $userdata[$row['meta_key']] = $row['meta_value'];
}