How do I write this PHP query the Drupal way (database abstraction)?
I think that you can review this answer:


  If you use db_query() all the time without directly inserting
  variables, but using the arguments.


I hope information be useful.