Efficiently escaping quotes in C before passing to mysql_query

前端 未结 3 1768
花落未央
花落未央 2020-12-11 10:38

In a nutshell I typically build a MySQL query within C using sprintf

i.e.

sprintf(sqlcmd,\"update foo set dog=\\\"lab\\\" where description=\\\"%s\\\         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-11 11:22

    Although MySQL has a mysql_real_escape_string() function, you should probably be using prepared statements instead, which allow you to use ? placeholders instead of real parameters, and then bind them to the real parameters before each execution of the statement.

提交回复
热议问题