Title: Coding Issue &#8211; Relational Databases
Last modified: August 21, 2016

---

# Coding Issue – Relational Databases

 *  [SergeBenard](https://wordpress.org/support/users/sergebenard/)
 * (@sergebenard)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/coding-issue-relational-databases/)
 * Hello.
 * My questions are:
    - 1) How do I approach creating relational database tables and maintain their
      relationships throughout the web app?
    - 2) Where in the documentation should I look for more information?
 * The [simplified database schema](http://twitpic.com/ciev04).
 * I want to be able to manage the Image Categories, Images, Image Comments and 
   the Canned Comments in the backend.
 * Again, the questions I have are:
    - 1) How do I approach creating relational database tables and maintain their
      relationships?
    - 2) Where in the documentation should I look for more information?
 * I am more than happy to clarify the question if there is any need to.
 * Thanks a lot gang.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/coding-issue-relational-databases/#post-3646239)
 * You will develop a plugin to interface with WP. You will access the database 
   using [$wpdb](http://codex.wordpress.org/Class_Reference/wpdb) methods. You could
   either create the tables manually with myPhpAdmin if this is a one off app, or
   via the plugin activation hook.
 * The relationships are defined by how you construct the SQL queries. You will 
   want to develop a series of functions that add an abstraction layer between procedural
   code and the database. Functions like `list_image_comments()` and such to establish
   relationships and to avoid writing mySQL queries every time you want something
   out of the database, just as WP does with it’s data. This is best done by defining
   class properties and methods, but not a requirement.
 * If you are looking for examples, you don’t need to look much farther than the
   WP source code itself.
 *  Thread Starter [SergeBenard](https://wordpress.org/support/users/sergebenard/)
 * (@sergebenard)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/coding-issue-relational-databases/#post-3646244)
 * This sounds exactly like what I needed to hear. I was having a difficult time
   wrapping my head around this issue.
 * To confirm that I have it understood, can you answer this for me please:
 * To make my app work, I’d be building the app as if it were stand-alone, but using
   the WordPress API and WP’s coding best practices?
 * For example:
 *     ```
       // Store table name in variable before creating it
       $table_name = $wpdb->prefix . "cannedcomments";
       ```
   
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/coding-issue-relational-databases/#post-3646264)
 * Generally, yes that is what I’m thinking. Of course, there will be departures.
   How they are handled is a judgment call, do your best. For example, in your example
   code snippet, you might choose to not use table prefixes for some reason. If 
   you have a valid reason, no problem. Without a logical reason, then yes, following
   WP best practice is a good idea.
 *  Thread Starter [SergeBenard](https://wordpress.org/support/users/sergebenard/)
 * (@sergebenard)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/coding-issue-relational-databases/#post-3646265)
 * Thank you very much, this is great. Thanks for your time!!
 *  [davekorpi](https://wordpress.org/support/users/davekorpi/)
 * (@davekorpi)
 * [13 years ago](https://wordpress.org/support/topic/coding-issue-relational-databases/#post-3646332)
 * I sooooo need help and happy to pay. I need a relational database that has a “
   key” of “customer number” that relates the database of information similar to
   that Serge described… Anyone interested in doing consulting? Is that allowed 
   to ask on this forum? You can find me everywhere on the web if you search provisional
   patent video course
 * Thanks a million!
 * THEN.. what I want to do is to be able to POPULATE this database with an embedded
   system that can only use HTML using a TCPIP stack using a wireless modem… Crazy
   right!!??

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Coding Issue – Relational Databases’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [Coding](https://wordpress.org/support/topic-tag/coding/)
 * [database](https://wordpress.org/support/topic-tag/database/)
 * [db](https://wordpress.org/support/topic-tag/db/)
 * [multidimensional](https://wordpress.org/support/topic-tag/multidimensional/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [relation](https://wordpress.org/support/topic-tag/relation/)
 * [relational](https://wordpress.org/support/topic-tag/relational/)
 * [Relationship](https://wordpress.org/support/topic-tag/relationship/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 5 replies
 * 3 participants
 * Last reply from: [davekorpi](https://wordpress.org/support/users/davekorpi/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/coding-issue-relational-databases/#post-3646332)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
