How do I retrieve external data from MS SQL from a Wordpress Blog?


Question

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
5
2/24/2010 6:08:30 PM

Accepted Answer

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.

3
2/24/2010 6:06:42 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon