【发布时间】:2019-04-13 19:18:29
【问题描述】:
我检查了 $posts_not_to_select 中的数据是简单数组,其他一切都很好,但它显示如下所示的错误:
异常 #0 (Zend_Db_Statement_Exception):SQLSTATE[42000]:语法 错误或访问冲突:1064 您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册 在 'WHERE
entity_idNOT IN (SELECT post_id FROM mst_blog_store_post WHERE NOT stor' 在第 1 行,查询是:SELECT * FROMmst_blog_post_entityORDER BYcreated_atDESC LIMIT 1 WHEREentity_idNOT IN(从 mst_blog_store_post 中选择 post_id store_id = 1)
$posts_not_to_selectssql1 = "SELECT post_id FROM mst_blog_store_post WHERE NOT store_id = $storeID";
$posts_not_to_select12 = $connection->fetchAll($posts_not_to_selectssql1);
$posts_not_to_select = array();
foreach ($posts_not_to_select12 as $key => $value){
$posts_not_to_select[$key] = $value['post_id'];
}
"SELECT * FROM `mst_blog_post_entity` ORDER BY `created_at` ASC LIMIT 1 WHERE `entity_id` NOT IN ( '" . implode( "', '" , $posts_not_to_select ) . "' )"
【问题讨论】:
-
无论您选择何种数据库,所有 SQL 查询都遵循某种形式的语法。如果你忽略你选择的数据库语法,你不会走得太远:-(——而且,你这里的查询似乎比绝对必要的要多。