I just simply want to execute a SQL sentence inside of a post (i am using EXEC-PHP widget for that).

The problem are the quotes when i want to do something like


"select * from Table where name='$my_name'";

getting wrong quotes.... select * from Table where name=‘hello‘

i have tried streepslashes_deep, addslashes, stripslashes...

I think it shouldnt be so difficult... maybe its not my best day

any help?


3 Answers 3


if you're communicating with the WordPress database itself, try using $wpdb->prepare() on your select string before running it as $wpdb->query() - it should format it for you.

Further reading: Codex


Perhaps the plugin is modifying your single quotes. Double quotes are valid in SQL. What happens if you use double quotes and escape them?

e.g. "select * from Table where name=\"$my_name\"";


Try seperating and concatenating stringss:

'select * from Table where name="'.$my_name.'"'; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.