views:

234

answers:

2

In Wordpress, how would I pull data from an external Microsoft SQL database to display as a read only table?

To be clear, this is not a question on how to convert Wordpress over to MS SQL, but rather how to pull data for a specific widget from a source outside the primary Wordpress DB. The data I need to pull from happens to be in a MS SQL database.

For the sake of example, let's say that I need to pull store locations and hours:

/* Retrieve store locations from the external MS SQL database*/

SELECT id, name, address, city, state, zip, phone, openingTime, closingTime
FROM locations
ORDER BY name

And display that data into a table on a Wordpress page:

<table>
<tr>
    <th>Store Name</th>
    <th>Address</th>
    <th>Store Hours</th>
</tr>

<!-- Display rows of store locations here -->

</table>
+1  A: 

Wordpress runs on PHP and so you need to use a PHP provider for SQL Server. See Accessing SQL Server Databases with PHP.

If you host Wordpress on Linux, you need FreeTDS, see PHP mssql Requirements.

Remus Rusanu
Good resources! The Linux info is helpful for reference, but currently we're running Apache, PHP and Wordpress on a Windows server.
Dan Sorensen
the link has plenty examples how to connect, execute a query, retrieve the result and iterate the result and format output html. Do you need help on that part, or can you take it from here?
Remus Rusanu
No, that Microsoft page is quite helpful! I think its all I need, but I'm reviewing the page against my question before I select the answer and close the question.
Dan Sorensen
A: 

you should use triggers or database events.. that is really helpful. if you want fetch from only wordpress then use simple php mysql program

wordpressapi