Introduction
The MYSQLWrapper
class is a small and simple-to-use solution for accessing server side MySQL databases at a standard webspace that supports PHP and MYSQL.
I thought it would be useful because many of you have got those cheap PHP/MYSQL supported sites and want to use data at the client side.
SQL queries and non query commands proceed as follows:
- The client side C# program passes the needed SQL command to the server side script using HTTP request.
- The server side script performs SQL statement and returns the result, if there is any, back to the client.
- Now the client parses the returned data and creates a
Resultset
that behaves similar to the sqlDataReader
.
Using the Code
In order to implement this, you have to check two main parts:
- The PHP Script
- FTP the PHP Script up to your site
- Make changes to the script regarding specific MYSQL Server information, shown in this line of wrapper.php:
$W->assign("mysql.mydomain.com","sqluser","sqlpwd",$database,$statement);
- The client class
- Add the
CL_MYSQLWrapper
class to your project and make sure that you use namespace MYSQLWrapper
like this:
using MySQLWrapper;
Now you can use wrapper class easily to perform DDL, DQL and DML statements like this:
MySQLWrapper W = new MySQLWrapper("http://www.mydomain.com/wrapper.php");
MSWRecordSet R = W.Query("MYDB", "SELECT * FROM t_persons");
while (R.Read())
{
Console.WriteLine(R.Fields["F_Name"].ToString );
}
W.NonQuery("MYDB", "UPDATE t_persons SET F_Name='nobody'");
History
- 7th November, 2007: Initial post