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 Word开发者_高级运维press page:
<table>
<tr>
<th>Store Name</th>
<th>Address</th>
<th>Store Hours</th>
</tr>
<!-- Display rows of store locations here -->
</table>
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.
精彩评论