错误的SQL语法用一个简单的查询
问题描述:
这里是我的sql语句错误的SQL语法用一个简单的查询
SELECT ID, post_title, post_name, post_type
FROM `wp_posts`
WHERE `post_type` LIKE 'ep_e%'
我在phpMyAdmin运行这个SQL语句,完美的作品和(这里可能并不重要)返回106行
但是PHP中我使用数据库类运行此查询,但出现错误
您的SQL语法错误;检查对应于你的MySQL 服务器版本使用附近的“ep_e%”正确的语法
我试图插也仍然得到一个错误:(
$evt = 'ep_event';
SELECT ID, post_title, post_name, post_type
FROM `wp_posts`
WHERE `post_type` like '{$evt}'
我手动真是难倒这里: - /感谢提前
这里是我的类中的函数
protected function _prepareQuery()
{
if (!$stmt = $this->_mysqli->prepare($this->_query)) {
trigger_error("Problem preparing query ($this->_query) " .
$this->_mysqli->error, E_USER_ERROR);
}
return $stmt;
}
答
不知道它只是在你的后一个错字,但
select ID, post_title, post_name, post_type from `wp_posts` where `post_type` like {$evt}
应该
select ID, post_title, post_name, post_type from `wp_posts` where `post_type` like '{$evt}'
的通知的结尾。你已经在phpMyAdmin中添加了正确的内容,但是你从代码中粘贴的东西没有。
答
不知道这是否是或不...
你把刻度线,围绕“post_type”字段,在where子句中,而不是在场上的选择......我不不要以为这是一个本来需要的保留字。你有没有尝试删除所有的刻度线,即使在桌子周围......
也许在此之前的代码中存在问题。请发布您正在使用的实际PHP。 – Cfreak
你可以发布你的php代码吗? – smp7d
发布PHP代码。我闻到一个错字。 – Nikki9696