Wordpress 数据库查询错误 Call to a member function get_results() on null
在插件中的一个文件使用如下代码,无法查询
<body>
<?php
global $wpdb;
$sql = "";
$sql = "SELECT * FROM emgAdmin";
$sql = "$sql INNER JOIN wp_posts ON wp_posts.ID = emgAdmin.ID_OfPost ";
$ArrResult = $wpdb->get_results($sql);
while ($emgAdminResult = mysql_fetch_object($ArrResult)) {
echo($emgAdminResult->post_date);
}
?>
</body>
错误如下:
处理如下:
- 删除 global $wpdb
- 将以下代码添加到文件顶部
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/wp-db.php' );
完整代码如下:
<?php
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/wp-db.php' );
$sql = "";
$sql = "SELECT * FROM emgAdmin";
$sql = "$sql INNER JOIN wp_posts ON wp_posts.ID = emgAdmin.ID_OfPost ";
$ArrResult = $wpdb->get_results($sql);
while ($emgAdminResult = mysql_fetch_object($ArrResult)) {
echo($emgAdminResult->post_date);
}
?>
Wordpress 数据库查询错误 Call to a member function get_results() on null的更多相关文章
- Call to a member function allowField() on null 错误总结
Call to a member function allowField() on null 在空对象上调用 allowField() 没有该模型对象无法调用,需要创建相应的模型 错误版本: if ...
- PHP Lumen Call to a member function connection() on null 报错
(1/1) Error Call to a member function connection() on nullin Model.php line 1201at Model::resolveCon ...
- Call to a member function assign() on null
Thinkphp: 在子控制器里面写了一个构造函数,如下 //构造函数 public function __construct(){ echo 1; } 结果页面报错了 ----> Call ...
- 微调数据库表结构,30 分钟搞定 WordPress 数据库查询缓慢问题
同事的美女图片站,基于 WordPress 搭建的,因为数据越来越多,变得慢,我从 PHP slow log 里面看出是 WordPress 有些查询总是很慢,即使已经安装了页面缓存插件,但是由于页面 ...
- ECmall错误:Call to a member function get_users_count() on a non-object
问题描述: 在后台添加了一个app报错:Call to a member function get_users_count()Fatal error: Call to a member functio ...
- laravel和lumen数据库链接错误_FatalErrorException Call to a member function connection
FatalErrorException in Model.php line 3339: Call to a member function connection() on null 挺简单的一个lum ...
- Call to a member function select() on string错误
Call to a member function select() on string错误 Call to a member function select() on array错误 我也是 Get ...
- 数据库:MySQL实战;左链接;查询WordPress数据库中的文章内容
在1年前,我用学生价租了一个阿里云服务器(是真的便宜啊),自己在CentOS系统上用命令行搭了个WordPress的环境,开始了为期一个月使用自建博客的历程. 事实证明,博客在类似博客园这样的平台上写 ...
- Tapdata Cloud 2.1.5来啦:新增支持Amazon RDS数据库,错误日志查询更便捷,Agent部署细节再优化
需求持续更新,优化一刻不停--Tapdata Cloud 2.1.5 来啦! 最新发布的版本中,数据连接再上新,同时新增任务报错相关信息快速查询入口,开始支持 JVM 参数自定义设置. 更 ...
随机推荐
- linux 命令——24 Linux文件类型与扩展名
Linux文件类型和Linux文件的文件名所代表的意义是两个不同的概念.我们通过一般应用程序而创建的比如file.txt.file.tar.gz ,这些文件虽然要用不同的程序来打开,但放在Linux文 ...
- IOS 模仿有storyboard的项目控制器的创建
● 先加载storyboard文件(Test是storyboard的文件名) UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@ ...
- 【CF799B】T-shirt buying(一道很水的小根堆)
点此看题面 大致题意: 有\(n\)件T恤衫,告诉你每件T恤衫的价格以及它正面和反面的颜色(\(1≤\)颜色的编号\(≤3\)),现在有m个顾客,已知每个人想要的衣服的颜色(一件T恤衫只要有一面的颜色 ...
- 【BZOJ1972】[SDOI2010] 猪国杀(恶心的大模拟)
点此看题面 大致题意: 让你模拟一个游戏猪国杀的过程. 几大坑点 对于这种模拟题,具体思路就不讲了,就说说有哪些坑点. 题面有锅,反猪是\(FP\). 数据有锅,牌堆中的牌可能不够用,牌堆为空之后需一 ...
- SpringBoot操作MongoDB实现增删改查
本篇博客主讲如何使用SpringBoot操作MongoDB. SpringBoot操作MongoDB实现增删改查 (1)pom.xml引入依赖 <dependency> <group ...
- 【转】iOS 文件下载及断点续传
ios的下载我们可以使用的方法有:NSData.NSURLConnection.NSURLSession还有第三方框架AFNetworking和ASI 利用NSData方法和NSURLConnecti ...
- 【luogu P1983 车站分级】 题解
题目链接:https://www.luogu.org/problemnew/show/P1983 符合了NOIP命题的特点,知识点不难,思维量是有的. step1:把题读进去,理解.得到 非停靠点的等 ...
- 第一篇:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 0: invalid continuation byte
需求:python如何实现普通用户登录服务器后切换到root用户再执行命令 解决参考: 代码: def verification_ssh(host,username,password,port,roo ...
- 五、Shell 基本运算符
Shell 基本运算符 Shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符 关系运算符 布尔运算符 字符串运算符 文件测试运算符 原生bash不支持简单的数学运算,但是可以通过其他命令 ...
- DevOps - 版本控制 - Gogs
Gogs Gogs官网:https://gogs.io Gogs文档:https://gogs.io/docs Gogs配置文件手册:https://gogs.io/docs/advanced/con ...