【问题标题】:How to change mysql_fetch_assoc into mysqli [duplicate]如何将 mysql_fetch_assoc 更改为 mysqli [重复]
【发布时间】:2015-03-08 17:16:06
【问题描述】:

如何将其更改为 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'];
}

【问题讨论】:

标签: php mysql mysqli


【解决方案1】:

只需对代码进行简单的更改:

// 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'];
}

【讨论】:

  • 如何获取我的数据? $用户数据[2]; wokrs 但不是 $userdata['fist_name'];
  • "while($row=mysqli_fetch_array($get_user_data,MYSQLI_ASSOC)",使用这一行代替"while($row=mysqli_fetch_assoc($get_user_data))"
猜你喜欢
  • 2020-01-29
  • 1970-01-01
  • 1970-01-01
  • 2010-11-26
  • 2019-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多