Assigning the same parameter value multiple times in pdo execute

前端 未结 1 851
梦毁少年i
梦毁少年i 2021-01-24 16:24

I originally had an SQL statement, this:

SELECT *, COUNT(friend_one) AS pending_count , COUNT(friend_two) AS requests_sent   
FROM friends
WHERE friend_one OR fr         


        
相关标签:
1条回答
  • 2021-01-24 17:11

    Using PDO you have the ability to use named parameters, however in your question you want to use 1 parameters for multiple values and that means emulation has to be on:

    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
    

    Now you can do the following:

    $stmt = $db->prepare("SELECT * FROM table WHERE userid = :userid AND userid = :userid");
    
    $stmt->excecute([
      ':userid' => 1
    ]);
    

    Resulting in:

    "SELECT * FROM table WHERE userid = 1 AND userid = 1"
    
    0 讨论(0)
提交回复
热议问题