I’m needing to use PHP to access the MySQL database on my host from a C# project. I’m learning PHP and mysqli to be able to do this. I’m stuck about where to actually sort the information. The query comes from my C# app through a $_POST variable and gets the requested data. But then it seems like i’m limited as how to get it back to my app. I can either send it as one long string and reorganize it in C#. Or create complicated for loops and still need to do a lot of sorting on the C# side. I’m sure i’m just unfamiliar with PHP and mysqli. Can anyone recommend a workflow? Thanks.
Share
There’s many ways you can pass it back to your C# application. JSON and XML are very popular. For this answer I will discuss using JSON.
On the PHP side you will want to take your data and convert it into it’s JSON form with json_encode. On the C# side you will convert it from JSON into a C# object. While there are ways to do this built into C# (DataContractSerializer and JavaScriptSerializer), the best option in .NET due to implementation and performance is Newtonsoft’s Json.NET.
Updating… adding a rough example.
PHP
C# (using JSON.net/JObject… you could also make an actual object to deserialize to)