[wp-hackers] The WordPress schema
Travis Snoozy
ai2097 at users.sourceforge.net
Mon Nov 5 04:05:44 GMT 2007
On Sun, 04 Nov 2007 16:06:01 -0500, Blast o_O <neryver at infomed.sld.cu>
wrote:
> Thanks to all answers ;)
>
> Do you know where can I find a picture about the schema!!!??? :)
> I'm tryin to install DBDesigner in my Ubuntu but I have lots of
> troubles reading MySQL servers ;)
>
> Thanks to all ;)
> B.
>
If you're writing a plugin, you really, really, really should try to
avoid messing with the WordPress-stored data by hand (which is the only
reason you would need to know about the schema). Use the WordPress
APIs[1][2] to alter and read what you need about users, posts,
tags/categories, links, comments and options. This will make your code
more robust if the schema changes in the future.
If you absolutely must query the tables directly, the easiest way to
see how they work is to either view the schema file[3], or install
Apache, PHP, MySQL and WordPress on your local box, and look at the
database WordPress creates. The MySQL manual[4] should have all the
information you need about SQL syntax and the DESCRIBE TABLE
and SELECT commands. No, it won't describe the relationships for you --
you have to match the foreign keys up yourself, since the FK constraints
are not explicitly set in this schema (which means you also won't be
able to "get a picture" -- the connections will be missing). It's not
hard to figure out what the fields do, and which fields are foreign key
references, just from the field names. It's what developers like to call
"self-documenting". ;)
Again, it's not too hard -- however, it does provide a bar, whether
intentional or not. You have to grok RDBMSs and English at at least a
minimal level, and have a little bit of developer's intuition, before
you can start playing with these matches.
As to your other question: you cannot get the schema for a site's
database (e.g., "craigslist"), unless you have access to the back-end
SQL servers or a person with inside knowledge -- that information is
private. In any case, unless you're running software *on* that site,
the scheme it uses is completely irrelevant. There is no such thing as
a "site schema".
--
Travis
In Series maintainer
Random coder & quality guy
<http://remstate.com/>
[1] http://codex.wordpress.org/Function_Reference
[2] All the files in /wp-include of your WordPress installation
[3] /wp-admin/includes/schema.php as previously mentioned
[4] http://dev.mysql.com/doc/
More information about the wp-hackers
mailing list