How to remove single quotes in prepare statement?

后端 未结 5 2062
余生分开走
余生分开走 2020-12-22 11:16

My query is like this :

$group_id = $session[\'group_id\'];

$sql = \"SELECT *
        FROM notification 
        WHERE group_id IN(?)\";

$result = $this-&g         


        
5条回答
  •  礼貌的吻别
    2020-12-22 12:03

    You either need to dynamically add in as many ? as you have values in the array...

    Or stop using a prepared query and do something like the following:

    $group_id = $session['group_id'];
    
    $sql = "SELECT *
        FROM notification 
        WHERE group_id IN (".implode($group_id,",").")";
    

    If the data hasn't come from a user you don't necessarily need to use a prepared query to make sure the data is safe. But if necessary you could do an is_numeric() check before the query to see if the data is valid.

提交回复
热议问题