[英]“Syntax error” when using Zend_Db to query MySQL database
This is my query:这是我的查询:
$query = $db
->select()
->from(array('ns' => 'news_subscriber'),
array('ns.id', 'ns.subscriber_email')
)
->where('ns.id NOT IN (?)',
$db
->select()
->from(array('nss' => 'news_subscribers_has_news_letter_content'),
array('nss.news_subscribers_id')
)
->where('nss.news_letter_content_id =' , $id)
);
$subscribers = $db->fetchAll($query);
I am getting this error:我收到此错误:
Syntax error or access violation 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))))' at line 1`
I feel the problem is in the "IN".我觉得问题出在“IN”中。
Any ideas?有任何想法吗?
Your query has multiple errors.您的查询有多个错误。
->where('nss.news_letter_content_id =', $id)
You forgot the ?
你忘了
?
after the =
. =
之后。
->where('ns.id NOT IN (?)', $db->select()...
I'm pretty sure that you have to convert the subquery object to an array first.我很确定您必须先将子查询 object 转换为数组。
$subscribers = $db->fetchAll($db->select()->from('news_subscriber ns, subscriber_email se')
->where('ns.id NOT IN ('.$db->select()->from( 'news_subscribers_has_news_letter_content nss') ->where('nss.news_letter_content_id =',$id))));
I dont use array in my select.我不在我的 select 中使用数组。 See if this is helpful.
看看这是否有帮助。
you may write your query like this..please check below.你可以这样写你的查询..请在下面检查。
$subscribers = $db->fetchAll($db->select()->from(array('ns' => 'news_subscriber','nss'=> 'news_subscribers_has_news_letter_content'),
array('ns.id',
'ns.subscriber_email','nss.news_subscribers_id'))
->where('ns.id NOT IN (?) AND 'nss.news_letter_content_id =',$id);
Thanks.谢谢。
Note that you can always see the whole query to see where is the problem.请注意,您始终可以查看整个查询以了解问题出在哪里。
echo (string)$query;
// die();
are you sure that all the variables that you have used in your query are getting a value, most of the times this error occurs if the values of the variables in the query are uninitialized or "" in case of a string......... Also in this case I think you have an extra ')' in the end hope that helps您确定您在查询中使用的所有变量都得到了一个值吗?大多数情况下,如果查询中变量的值未初始化或“”在字符串的情况下,则会发生此错误..... ....同样在这种情况下,我认为你最后有一个额外的')'希望有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.