function to sanitize input to Mysql database

前端 未结 5 2145
春和景丽
春和景丽 2020-12-14 03:19

I am trying to put a general purpose function together that will sanitize input to a Mysql database. So far this is what I have:

function sanitize($input){
          


        
5条回答
  •  旧巷少年郎
    2020-12-14 03:28

    Magic quotes are deprecated. Turn them off if you can :).

    The second part addslashes and mysql_real_escape_String does pretty much the same (similar) thing. Just try

    addslashes( '\\')
    // and
    mysql_real_escape_string( '\\')
    

    Result should be \\ so if you use

     mysql_real_escape_string( addslashes( '\\'))
    

    you should get \\ (or '\\\\' as string). Use only mysql_real_escape_string (better) OR addslashes, never both.

    I recommend to use PDO instead of raw functions and manual escaping.

提交回复
热议问题