An into to using $wpdb with your own database tables

  • 832 views
Uploaded on

Presented at WordUp AZ, this was a quick intro to using $wpdb to work with your own database tables from inside WordPress

Presented at WordUp AZ, this was a quick intro to using $wpdb to work with your own database tables from inside WordPress

More in: Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
832
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
1
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Saturday, March 16, 13
  • 2. HI, I’M JOHN • Founder @ 9seeds.com • WordPress Developer • Viva, Las VegasSaturday, March 16, 13
  • 3. The Problem You’ve got database tables you need to access from inside wordpressSaturday, March 16, 13
  • 4. What are my options? • Convert all the data to custom post types • Write some (potentially) janky direct database access queries in to your theme or plugin • Or, you can check out $wpdbSaturday, March 16, 13
  • 5. What is $wpdb?Saturday, March 16, 13
  • 6. $wpdb “WordPress provides a global variable, $wpdb, which is an instantiation of the class already set up to talk to the WordPress database.”Saturday, March 16, 13
  • 7. Let’s dig in!Saturday, March 16, 13
  • 8. My ContactsSaturday, March 16, 13
  • 9. Some DataSaturday, March 16, 13
  • 10. First up We need to tell WordPress about our new tableSaturday, March 16, 13
  • 11. Adding our tableSaturday, March 16, 13
  • 12. Accessing our table dataSaturday, March 16, 13
  • 13. get_results()Saturday, March 16, 13
  • 14. Saturday, March 16, 13
  • 15. Which turns...Saturday, March 16, 13
  • 16. Into...Saturday, March 16, 13
  • 17. Adding data to our customSaturday, March 16, 13
  • 18. Start with a formSaturday, March 16, 13
  • 19. Start with a formSaturday, March 16, 13
  • 20. Check your nonce!Saturday, March 16, 13
  • 21. ... from the codex All data in SQL queries must be SQL-escaped before the SQL query is executed to prevent against SQL injection attacks. This can be conveniently done with the prepare method.Saturday, March 16, 13
  • 22. query() and prepare()Saturday, March 16, 13
  • 23. Our data addedSaturday, March 16, 13
  • 24. This is just the beginning!Saturday, March 16, 13
  • 25. Resources • http://codex.wordpress.org/Class_Reference/wpdb • http://www.slideshare.net/vegasgeekSaturday, March 16, 13
  • 26. Thank You! john@9seeds.com - @vegasgeekSaturday, March 16, 13