ASP
  Home arrow ASP arrow Page 3 - Using MySQL with ASP
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
ASP

Using MySQL with ASP
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2008-10-14

    Table of Contents:
  • Using MySQL with ASP
  • Connecting with ASP
  • Script Explained
  • Conclusion

  • 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


    Using MySQL with ASP - Script Explained


    (Page 3 of 4 )


    To start with, we declare that we are using the VBScript language, and then we start the HTML page:


    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="Templates/guestbook.dwt.php" codeOutsideHTMLIsLocked="false" -->

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <!-- InstanceBeginEditable name="doctitle" -->

    <title>Untitled Document</title>

    <!-- InstanceEndEditable -->

    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->

    <link href="user.css" rel="stylesheet" type="text/css" />

    </head>


    <body>

    <table width="100%" border="1">

    <tr>

    <td colspan="2" class="welcomeheader">Welcome to Davids Website </td>

    </tr>

    <tr>

    <td colspan="2"><!-- InstanceBeginEditable name="EditRegion3" -->


    Then we build a table that will host the entries of the guest book:


    <table width="100%" border="0">

    <%



    Then we finally start the ASP. First we set up the connections:



    Set conx = Server.CreateObject("ADODB.Connection")

    Set rs = Server.CreateObject("ADODB.Recordset")



    The DSN name or data source name also needs to be added in the initial connection set up stage:



    conx.Open "DSN=mysqlasp" ' Data source name


    We then start to build the SQL query that will extract all the records from the database:


    strSQL = "SELECT * FROM guests"



    Then we execute the statement and start a do while loop. This loop will run until it reaches the end of file:


    ' Execute SQL statement

    Set rs = conx.Execute(strSQL)

    Do while not rs.eof

    %>


    As it is iterating through the result set, the the code builds a dynamic set of rows that contains the name, comment and date of each entry that was made in the database:


    <tr>

    <td width="13%" bgcolor="#999999"><strong>Name:</strong></td>

    <td width="87%"><% Response.Write rs("name") %></td>

    </tr>

    <tr>

    <td bgcolor="#999999"><strong>Comment:</strong></td>

    <td><% Response.Write rs("comment") %></td>

    </tr>

    <tr>

    <td bgcolor="#999999"><strong>Date:</strong></td>

    <td><% Response.Write rs("dateAdd") %></td>

    </tr>

    <tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    </tr>


    Finally, the database connection is closed and the conx variable is released:


    <%

    rs.MoveNext

    loop



    conx.close ' Close database connection

    Set conx = nothing 'obj variable released


    %>

    </table>

    <!-- InstanceEndEditable --></td>

    </tr>

     

    <tr>

    <td colspan="2" class="copy">&copy;2008</td>

    </tr>

    </table>

    </body>

    <!-- InstanceEnd --></html>

    More ASP Articles
    More By David Web


       · Friends I'm devouring my own 2 ever since What happens when someone with a...
       · Friends I'm devouring my own 2 ever since What happens when someone with a...
     

    ASP ARTICLES

    - Using MySQL with ASP
    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek