将sql查询写为PDO语句

时间:2020-12-03 19:24:27

while updating some of my SQL queries I ran into one which I have no clue how to translate to a PDO statement.

在更新我的一些SQL查询时遇到了一个我不知道如何转换为PDO语句的问题。

$header = $db_handle->runQuery("
        SELECT event_name,location,subject,details, $user_table.user_login AS Received_From,event_start_time,event_end_time,
            CASE WHEN status = '1' THEN 'Accepted'
                  WHEN status = '2' THEN 'Cancelled'
                  ELSE 'Pending' END as status,datetime AS Invite_Date,meeting_date
            FROM $event_table
        WHERE user_id = $user_ID
");

my main issue is with the AS and CASE WHEN THEN statements.

我的主要问题是AS和CASE WHEN THEN语句。

What I have so far:

到目前为止我所拥有的:

$stmt = $dbHandle->prepare(
            "
            SELECT event_name, subject, details, location, meeting_date, event_start_time, event_end_time
            FROM wp_request_event
            WHERE sender_id = ?
            ");
    $stmt->execute([$user_ID]);
    $header = $stmt->fetchAll();

Anyone any help or pointers?

任何人的帮助或指针?

1 个解决方案

#1


0  

AS and CASE WHEN THEN statements are totally irrelevant to PDO. You can keep them with your PDO statement as well.

AS和CASE那时这些陈述与PDO完全无关。您也可以将它们与PDO语句保持一致。

the only issue, as it was pointed out in the comments, is a table name, which I hope you can put in the query as is, without storing it in a variable

正如评论中指出的那样,唯一的问题是表名,我希望你可以按原样放入查询,而不将其存储在变量中

#1


0  

AS and CASE WHEN THEN statements are totally irrelevant to PDO. You can keep them with your PDO statement as well.

AS和CASE那时这些陈述与PDO完全无关。您也可以将它们与PDO语句保持一致。

the only issue, as it was pointed out in the comments, is a table name, which I hope you can put in the query as is, without storing it in a variable

正如评论中指出的那样,唯一的问题是表名,我希望你可以按原样放入查询,而不将其存储在变量中