How to insert a php code snippet in mysql database

后端 未结 3 1852
野的像风
野的像风 2020-12-22 06:25

I have a php code snippet like below :

function is_ancestor_of( $page_name = null, $post ) {

if(is_null($page_name))
return false;

// does         


        
3条回答
  •  余生分开走
    2020-12-22 07:08

    Yeah, you can do this. Multiple ways:

    1. PDO - that's the best option actually. Study this topic in the PHP manual as this can be a lot more help than just protecting your MySQL queries in PHP from breaking.
    2. addslashes() - adds slashes to escape characters. This won't break your MySQL query for sure.
    3. mysql_real_escape_string()
    4. mysql_escape_string()

    EDITED Emphasized PDO as compared to the previous version of this answer as PDO is far more safer than the other options and there is a lot more to it which can be used while working with PHP and MySQL.

提交回复
热议问题