catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Medoo::raw() is not working #667

Closed neckarpixel closed 6 years ago

neckarpixel commented 6 years ago

Hey Cat, thanks for your great development, i really like Medoo.

Today I've noticed (while looking for the doku) that the new 1.5 version is released. But the raw() function doesn't work.

I've tried your example:


$database->select('account', [
    'user_id',
    'user_name'
], [
    'datetime' => Medoo::raw("DATE_ADD(:today, INTERVAL 10 DAY)", [
        ':today' => $today
    ])
]);

Result: blank page, even if I use the debug(), last() function.

I'm trying to run a query like that select WEEKDAY( FROM_UNIXTIME( timestamp ) ) as weekday from table ... with following code

$database->select("data(content)", [
    "[>]users(user)" => ['content.lastmodifiedby' => 'id']
    ],                                      
    [   
        "content.id(dbid)",
        "content.timestamp",
        "content.sorting",
        "content.lastmodifiedby",
        "user.fullname(lastmodifiedbyname)",
        "weekday" => Medoo::raw('WEEKDAY ( FROM_UNIXTIME ( <content.timestamp> ) )'),
    ],                          
    [
        "userid"    => 1,
        "ORDER" => [
            "content.sorting" => "ASC"
        ]
    ]
);

Any ideas?

thx

catfan commented 6 years ago

What's your $database->error() output?

neckarpixel commented 6 years ago

Query

$database->select("data(content)",[
    "[>]users(user)" => ['content.lastmodifiedby' => 'id']
    ],                                              
    [   
        "content.id(dbid)",
        "content.timestamp",
        "content.status",
        "content.process",
        "content.description",
        "content.duration",
        "content.lastmodified",
        "content.lastmodifiedby",
        "content.paidjob",
        "content.sorting",
        "content.pinned",
        "user.fullname(lastmodifiedbyname)",
        "weekday" => Medoo::raw('WEEKDAY ( FROM_UNIXTIME( <content.timestamp> ) )'),
    ],                          
    [
        "weekday" => date('w',time()),
        "userid"    => '1',

        "ORDER" => [
            "content.sorting" => "ASC"
        ]
    ]
);

Error Output array(3) { [0]=> string(5) "00000" [1]=> int(1054) [2]=> string(42) "Unknown column 'weekday' in 'where clause'" }

catfan commented 6 years ago

@dhe This error is about "weekday" in $where. Remove it, or add table name to identify from which table.

neckarpixel commented 6 years ago

You're right: it is not possible to use a dynamic generated virtual table field inside the same query in where clause. Sorry for that issue.