数据库
首页 > 数据库> > mysql-$wpdb SELECT查询返回COUNT?

mysql-$wpdb SELECT查询返回COUNT?

作者:互联网

我对使用WordPress很陌生,但是在获得预期结果方面遇到了问题.我正在尝试从WordPress数据库中提取数据,因此我正在使用$wpdb.以下是我所拥有的:

global $wpdb;
echo $wpdb->query("SELECT * FROM wp_users");

它不回显所有用户,而是返回表中的用户数.如果添加“ WHERE id = some number”,它将回显该ID号.

怎么了?如何从表中选择所有内容?

谢谢.

解决方法:

The function returns an integer corresponding to the number of rows
affected/selected. If there is a MySQL error, the function will return
FALSE. (Note: since both 0 and FALSE can be returned, make sure you
use the correct comparison operator: equality == vs. identicality ===)

您可以使用get_results获取所有记录

 global $wpdb;
 $users=$wpdb->get_results( "SELECT * FROM wp_users" );
print_r( $users);

手册Class_Reference wpdb

标签:wpdb,wordpress,mysql
来源: https://codeday.me/bug/20191030/1968583.html