I'm working on a WordPress plugin and recently I have planned to migrate from SQL to $wpdb
. I'm using a method called $wpdb->prepare
instead of mysql_real_escape_string
but it does not work.
Here is what I tried:
Code:
echo $fetch_row;
Output:
a:5:{s:9:"task_name";s:10:"Backup Now";s:9:"mechanism";s:10:"singleCall"
Code:
echo mysql_real_escape_string( $fetch_row )
Output:
'a:5:{s:9:\"task_name\";s:10:\"Backup Now\";s:9:\"mechanism\"
After mysql_real_escape_string
function executed you can see the difference in the string.
I came along this question on stackexchange so I used $wpdb->prepare($fetch_row)
but the output did not change, it is just like the input.
Suggest me where I'm doing mistakes.
$wpdb->prepare
is not a direct replacement formysql_real_escape_string
, it has more in common withsprintf
/printf
, and is a little more involved