As I understand it, OData is just a standardized way to expose relational data RESTfully. If I've got a PHP application, it should be able to process those RESTful requests and manipulate a MySQL database based on the request data and then return an ATOM feed. First, are the preceeding statements correct? Second, does a PHP library to do this already exist or would I have to create my own?
If I have completely misunderstood these technologies and my question doesn't make sense, please feel free to let me know.
Data can be fetched from MySQL tables by executing SQL SELECT statement through PHP function mysql_query. You have several options to fetch data from MySQL. The most frequently used option is to use function mysql_fetch_array(). This function returns row as an associative array, a numeric array, or both.
With PHP, you can connect to and manipulate databases. MySQL is the most popular database system used with PHP.
php $servername = "localhost"; $username = "username"; $password = "password"; try { $conn = new PDO("mysql:host=$servername;dbname=newDB", $username, $password); // setting the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "CREATE DATABASE newDB"; // using exec() ...
OData is a way of exposing all sorts of structured data over an HTTP interface. The underlying repository for data may be relational or not. For example, when using WCF Data Services on top of SQL Server it's certainly a relational data set, but the OData endpoints in SharePoint Server 2010 or on Windows Azure Table Storage run on top of other data models. The high order bit is to make all data available in a web-friendly way.
As for your specific question about MySQL/PHP, there is an OData client for PHP but to my knowledge there isn't a server implementation available. I know there is a MySQL provider for ADO.NET, maybe if it has Entity Framework support you can use WCF Data Services, but that means you'd be running on .NET and not on PHP, don't know if it's acceptable for your situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With