Php 无效的SQL语法错误

Php 无效的SQL语法错误,php,sql,cakephp,Php,Sql,Cakephp,几周前,我的代码还不错,但最近我无法在我的web应用程序(使用CakePhp构建)上加载测试数据库 这就是错误: 警告(512):SQL错误:1064:您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,了解 右语法,用于将blogsASBlogON (Songblog\u id=blogid),其中第1行的1=1' [CORE/cake/libs/model/datasources/dbo_source.php,第684行] 警告(512):SQL错误:1064:您的SQL语法有错误

几周前,我的代码还不错,但最近我无法在我的web应用程序(使用CakePhp构建)上加载测试数据库

这就是错误:

警告(512):SQL错误:1064:您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,了解 右语法,用于将blogsAS
Blog
ON (
Song
blog\u id
=
blog
id
),其中第1行的1=1' [CORE/cake/libs/model/datasources/dbo_source.php,第684行]

警告(512):SQL错误:1064:您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,了解 使用near')的正确语法,其中1=1 ORDER BY
Song
postdate
第1行的描述限制为100' [CORE/cake/libs/model/datasources/dbo_source.php,第684行]

您的错误如下:

Library.user_id =)
也许您想将其更改为:

Library.user_id ='$user_id')

您没有Library.userid列的条件:

Library.user_id =)

您需要在等号的右侧指定一个值

似乎未将
用户id
的某些值传递到查询中:

`Library`.`user_id` =)
//-----------------^^^^
这里可能缺少一些PHP变量,或者PDO参数没有正确绑定。

从'songs'选择COUNT(*)作为'COUNT',从'Song'选择'Song'
SELECT COUNT(*) AS `count` FROM `songs` AS `Song` 
left JOIN libraries AS `Library` 
ON (`Song`.`id` = `Library`.`song_id` AND `Library`.`user_id` =) <-- HERE's something missing
LEFT JOIN `blogs` AS `Blog` ON (`Song`.`blog_id` = `Blog`.`id`) WHERE 1 = 1

SELECT *, 
Blog.id FROM `songs` AS `Song` left JOIN libraries AS `Library` 
ON (`Song`.`id` = `Library`.`song_id` AND `Library`.`user_id` =) <-- HERE's something missing
WHERE 1 = 1 ORDER BY `Song`.`postdate` desc LIMIT 100
将库作为“库”左键联接
在(`Song`.`id`=`Library`.`Song\u id`和`Library`.`user\u id`=)上,由于这是一个CakePHP问题,我的答案将从框架的范例开始。然而,考虑到您的SQL输出,您要么没有使用CakePHP,要么正在做一些绝对不允许的事情

请发布Find语句,说明您正在使用build this SQL语句,并且您的
博客有许多关系。除非您使用的是查询方法,否则我认为在使用CakePHP find约定构建这种类型的SQL语句之前,您会遇到一个PHP错误。如果您正在使用
query
方法查找数据,则不要这样做。这是一个简单的查询,可以使用CakePHP轻松完成

您的库模型应该如下所示:

public $hasMany => array('Blog');
发现:

$this->Library->find(
    'all',
    array(
        'conditions' => array(
            '1' => 1 //Not sure why you have Where 1=1
        )
        'order' => "Library.name DESC",
        'limit' => 100
    )
);
public $hasMany => array('Blog');
$this->Library->find(
    'all',
    array(
        'conditions' => array(
            '1' => 1 //Not sure why you have Where 1=1
        )
        'order' => "Library.name DESC",
        'limit' => 100
    )
);