Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Bridging the Gap: Talking to MySQL From VB...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Bridging the Gap: Talking to MySQL From VB.NET Through PHP and XML
By: Nicholas Clayton
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 33
    2004-02-04

    Table of Contents:
  • Bridging the Gap: Talking to MySQL From VB.NET Through PHP and XML
  • An Adventure in VB.NET
  • PHP: Talking the Universal Language
  • What's Said and Done in the End

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Bridging the Gap: Talking to MySQL From VB.NET Through PHP and XML - PHP: Talking the Universal Language


    (Page 3 of 4 )

     

    Now that this is out of the way, we can create our php page to generate the XML. We will assume that data has been entered into the database through a different php page, so all we are concerned about is pulling the data that already exists. The steps we need to follow to generate the XML file are:

    1) Check for an Access Key.
    2) Validate the Access Key. In our case, we are checking for a value of "12345".
    3) Start the XML document.
    4) Connect to MySQL and select the proper database.
    5) Query the table for the desired information.
    6) Loop through the recordset and create XML containing the retrieved data.
    7) Close the database connection
    8) Close the XML document.


    <?
     
    //getmessagelist.php
     
     // Make sure that there is an 
     //Access Key in the post data
     If($_POST['acc'] != '') 
     {
      If($_POST['acc'] == "12345") 
      // Check for the correct Key
       $auth = 1;
       // Key is correct, this is a 
       //valid request
      Else
       $auth = 0;
       //Invalid request
     }
     Else
      $auth = 0;
      //Invalid request
     
      //If the request is valid, 
      //produce an XML string 
      //containing the requested information
      If($auth == 1) {
     
      // Start the xml document
      echo "<?xml version=\"1.0\" encoding=\"UTF-8\"

    n";
      echo "<Messages>n";
     
      //Connect to the database and select the table
      $db = mysql_connect("host","username","password");
      mysql_select_db("database");
     
      //Query the table for details about the message
      $res = mysql_query("SELECT `fname`, `lname`, `email`, `date_submitted`, `time_submitted`,`MsgID` FROM `tblMessages` WHERE `Status` = ".$_POST['view']." ORDER BY `date_submitted`, `time_submitted`");
     
      //If information exists, write it out as XML
      If($rs = mysql_fetch_row($res)) {
       do {
        echo "<Message>n";
        //This is the table name
        echo "<MsgID>".$rs[5]."</MsgID>n";
        //Field 1
        echo "<From>".$rs[0]." ".$rs[1]."</From>n";
        //Field 2
        echo "<Email>".$rs[2]."</Email>n";
        //Field 3
        echo "<MsgDate>".$rs[3]."</MsgDate>n";
        //Field 4
        echo "</MsgTime>".$rs[4]."</MsgTime>n";
        //Field 5
        echo "</Message>n";
        } while($rs = mysql_fetch_row($res)); 
       mysql_close(); 
      }
     
      Echo "</Messages>";
     }
    ? >

    More Visual Basic.NET Articles
    More By Nicholas Clayton


     

    VISUAL BASIC.NET ARTICLES

    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET (F...
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT