我试图使用MEDOO连接两个表,我面临的问题是我正在构建的查询没有返回任何数据(返回false)。我已经按照这个正常的SQL代码进行了查询
select posts.id, title, extract, img_principal, users.username, date, category, platform, url from posts, users where users.username in (select username from users where users.id = posts.author);
结果是这样的:
$lastPost = 10;
$database = new medoo([
'database_type' => 'mysql',
'database_name' => 'notijuegosdb',
'server' => 'localhost',
'username' => 'root',
'password' => '',
'charset' => 'utf8'
]);
$database->select("posts", [
"[>]users" => ["author" => "users.id"]
], [
'posts.id',
'posts.title',
'posts.extract',
'posts.img_principal',
'users.username',
'posts.date',
'posts.category',
'posts.platform',
'posts.url'
], [
'posts.id[<]'=> $lastPost
]);
当我直接将SQL代码用于数据库时,它可以完美地工作,所以这可能是我构建查询的方法的问题。。。不确定出了什么问题。
提前非常感谢。
您可以使用用于复杂查询的查询medoo方法来存档此文件:
$postsData = $database->query("select posts.id, title, extract, img_principal, users.username, date, category, platform, url from posts, users where users.username in (select username from users where users.id = posts.author);")->fetchAll();
就像Medoo医生说的:
此函数用于特殊和自定义的SQL查询,用于复杂查询。对于将要插入的每个数据,请使用引号函数来防止SQL注入。
Medoo API