table 使用返回 false 而不是数据的 medoo 加入

table joining using medoo returning false instead of the data

我正在尝试使用 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 代码直接用于数据库时,它工作得很好,所以这可能是我构建查询的方式的问题...不确定哪里出了问题。

非常感谢。

您可以使用用于复杂查询的 query 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 文档所说:

This function is for special and customized SQL query that used for complex query. With each data that will be inserted, please use quote function to prevent SQL injection.

Medoo API