My site is based on Wordpress. To prevent SQL injection I need to sanitize data before the query. I have few questions about this.
1/ I read somewhere on stackoverflow, a person said that if we use get_results() for our query, we don't need to prepare() the sql query because data is already sanitized. So I'm not sure which case we must use prepare() and which case we don't need to use it.
$sql = prepare(....query...);
$wpdb->get_results($sql);
2/ Do we use prepare() with $wpdb->update() $wpdb->insert() $wpdb->get_row() ... or we just use prepare() for custom query like this $wpdb->query($wpdb->prepare(...query...))
3/ Say that I have a variable $data = $_POST['data'] . Which the best method below should I use to sanitize data before putting it in the query.
esc_sql($data);
or
sanitize_text_field($data);
or
mysql_escape_string($data);
or something else?
4/ Is there any safe query that we don't need to sanitize data for it or we have to sanitize all data before putting in the query?
Thank you.