简体   繁体   English

检索定制表数据

[英]Retrieve data from custom table

I am trying to use the following code to retrieve data from a custom table in WordPress: 我正在尝试使用以下代码从WordPress中的自定义表中检索数据:

$myrows = $wpdb->get_results( "SELECT id, name FROM mytable" );

The result set is empty, even though there is data in the table. 即使表中有数据,结果集也为空。 Getting data from the database for the WordPress internal tables works without a problem. 从数据库为WordPress内部表获取数据可以正常工作。

For example, the following works without a problem: 例如,以下内容可以正常工作:

$posts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type='post' ORDER BY comment_count DESC LIMIT 0,4");

Any thoughts on how to diagnose the issue? 关于如何诊断问题有什么想法?

If it's a problem with your SQL statement, an error will get echo ed out - where that goes in WordPress, I don't know. 如果您的SQL语句有问题,则会echo显出错误-我不知道WordPress中的错误。

WordPress does have a Error Logging widget you can install to help you debug your problem: http://wordpress.org/extend/plugins/error-log-monitor/ WordPress确实有一个错误记录小部件,您可以安装它来帮助您调试问题: http : //wordpress.org/extend/plugins/error-log-monitor/

This should explain how to set up the logging so you can see where the problem is coming from. 这应该说明如何设置日志记录,以便您可以查看问题的根源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM