I have a php code snippet like below :
function is_ancestor_of( $page_name = null, $post ) {
if(is_null($page_name))
return false;
// does it have a parent?
if (!isset( $post->post_parent ) OR $post->post_parent <= 0 )
return false;
//Get parent page
$parent = wp_get_single_post($post->post_parent);
if ( $parent->post_name == $page_name ){
echo $parent->post_name.' - '.$page_name;
return true;
} else {
is_ancestor_of( $page_name, $parent );
}
}
I just want to insert this whole code in mysql database table and again retriew it with this same formatting on the page again. When I simply insert this code in database using INSERT INTO query then the mysql syntax error occurs because the code breaks sql query because of special characters. Is there any way to do this??
Thanks.
Yeah, you can do this. Multiple ways:
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.