请帮助新手。我的脑袋坏了。 我在phpmyadmin中发出了mysql请求:
SELECT user_id FROM wp_usermeta WHERE meta_key = 'player' AND meta_value = 'yes'
并获取
user_id
1
30
28
22
26
12
这是正确的结果。我运行PHP脚本:
<?php
require 'connect.php';
$sql_planet="SELECT user_id FROM wp_usermeta WHERE meta_key = 'player' AND meta_value = 'yes'";
$result_planet = mysql_query($sql_planet);
while ($row_planet = mysql_fetch_object($result_planet)) {
print_r($row_planet);
}
?>
并获取
stdClass Object ( [user_id] => 108 ) stdClass Object ( [user_id] => 60 ) stdClass Object ( [user_id] => 48 ) stdClass Object ( [user_id] => 51 ) stdClass Object ( [user_id] => 7 ) stdClass Object ( [user_id] => 101 )
怎么了?
答案 0 :(得分:0)
我已使用mysqli
重新编写您的脚本:
$conn = mysqli_connect("your_server","your_user","your_pw","your_db");
if(!$conn) {
die("Connection failed: ".mysqli_connect_error());
}
$sql_planet="SELECT user_id FROM wp_usermeta WHERE meta_key = 'player' AND meta_value = 'yes'";
$result = mysqli_query($conn, $sql_planet);
while($row = mysqli_fetch_assoc($result)) {
echo "Id of user: ".row['user_id'];
}
mysqli_close($conn);