WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question

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

share|improve this answer

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\"";

share|improve this answer

Try seperating and concatenating stringss:

'select * from Table where name="'.$my_name.'"'; 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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