Click here to Skip to main content
15,884,877 members
Articles / Database Development / MySQL

C# MYSQLWrapper Class and PHPWrapper-Script

Rate me:
Please Sign up or sign in to vote.
4.19/5 (6 votes)
7 Nov 20071 min read 40.6K   377   32   9
Accessing the MYSQL Database at your webspace from any remote computer
Screenshot - wrapper.jpg

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:

  1. The client side C# program passes the needed SQL command to the server side script using HTTP request.
  2. The server side script performs SQL statement and returns the result, if there is any, back to the client.
  3. 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:

  1. 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);
    
  2. The client class
    • Add the CL_MYSQLWrapper class to your project and make sure that you use namespace MYSQLWrapper like this:
    C#
    using MySQLWrapper;
    

    Now you can use wrapper class easily to perform DDL, DQL and DML statements like this:

    C#
    // Instantiate Wrapper Class with your script URL
    MySQLWrapper W = new MySQLWrapper("http://www.mydomain.com/wrapper.php");
    
    // Query server side db and get your resultset
    MSWRecordSet R = W.Query("MYDB", "SELECT * FROM t_persons");
    
    // Print out results, in this case the field f_name
    while (R.Read())
    {
        Console.WriteLine(R.Fields["F_Name"].ToString );
    }
    
    // Make a non query and update something.
    W.NonQuery("MYDB", "UPDATE t_persons SET F_Name='nobody'");

History

  • 7th November, 2007: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralNeed mysql database also to see it working Pin
sudhirpatel24-Nov-10 1:04
sudhirpatel24-Nov-10 1:04 
Generalwrapper.php corrections to working Pin
werner.kremer21-Nov-07 12:38
werner.kremer21-Nov-07 12:38 
GeneralSecurity Pin
Markus Foss13-Nov-07 21:17
Markus Foss13-Nov-07 21:17 
GeneralRe: Security Pin
cellarjay15-Nov-07 9:54
cellarjay15-Nov-07 9:54 
GeneralRe: Security Pin
Markus Foss15-Nov-07 21:29
Markus Foss15-Nov-07 21:29 
GeneralRe: Security Pin
TorstenFrings16-Nov-07 3:57
TorstenFrings16-Nov-07 3:57 
Questionwhat about the transfer of binary Data? Pin
loungedj8-Nov-07 8:44
loungedj8-Nov-07 8:44 
Good idea. A webservice without all the overhead. But:
Is it possible to post and get binary data (images) that way, or need I include changes?
AnswerRe: what about the transfer of binary Data? Pin
cellarjay12-Nov-07 7:43
cellarjay12-Nov-07 7:43 
AnswerRe: what about the transfer of binary Data? Pin
werner.kremer24-Feb-08 9:32
werner.kremer24-Feb-08 9:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.