$wpdb is not initiating

时间:2018-02-14 作者:ishtiaq

我是wordpress新手,想创建一个插件,但是$wpdb 未启动,我正在使用wordpress版本4.9.4

这是我的代码片段

global $wpdp;
$sql    = \'SELECT * From \'.$wpdp->prefix.\' my_first_plugin\';
$result = $wpdp->get_results($sql); 

1 个回复
SO网友:Beee

您在代码示例中错误地编写了$wpdb(3x)。如果它是一个精确的副本,它将永远不会工作。SQL中前缀后面有一个空格。”不应该在那里。“From”应该是所有的大写字母。

尝试以下操作:

global $wpdb;
$sql    = \'SELECT * FROM \' . $wpdb->prefix . \'my_first_plugin\';
$result = $wpdb->get_results($sql); 

结束

相关推荐

Database Name Change

我读到,使用wp\\uu之外的其他东西作为数据库前缀更安全,所以我下载了我的数据库前缀wp\\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu