Binding variable for column name in PHP for Postgresql query

前端 未结 1 1470
遇见更好的自我
遇见更好的自我 2021-01-21 09:13

I need to dynamically generate the column name I need to update in Postgresql from PHP. Here\'s the code and the error:

$Col = \"dog_\".$Num.\"_pic\";
$query_par         


        
1条回答
  •  不思量自难忘°
    2021-01-21 09:48

    You can't bind columns names in your query:

    $sql = "UPDATE users 
            SET `:dog_col`=:dog_path
            WHERE `username`=:user_id_";
    

    In this case you must use a variable like this:

        $column = 'myColumn';
    
        $sql = "UPDATE users
                SET $column = :dog_path
                WHERE username = :user_id_";
    

    0 讨论(0)
提交回复
热议问题