Database Access from HTML Page

Posted on 2011-10-08
Last Modified: 2012-06-27
Is it possible to access, read, and display a single database value from inside of a standard XHTML page without changing the page extension from .HTML?  I know I could change it to ASP, ASPX, PHP, etc. and do it that way, but I would like to preserve the existing URL structure.  I realize I could also do it in an IFRAME, but the value being returned may be differing sizes.  What are my options experts?

Question by:PowerEdgeTech
    LVL 9

    Expert Comment

    ...don't do it... you can pull that off with Javascript like so (Assuming MSSQL):

    var connection = new ActiveXObject("ADODB.Connection") ;
    var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";
    var rs = new ActiveXObject("ADODB.Recordset");
    rs.Open("SELECT * FROM table", connection);

    Open in new window

    but don't do it. You need a preprocessor (ASP, PHP, etc.) for security and stability... plus not everyone has JS enabled. Nevermind the page has the connection info in plain text FFS
    LVL 32

    Author Comment

    Thanks.  So, while it is technically "possible", it is so impractical that we could say "no, this can't be done"?  Is this the answer you're giving me?
    LVL 82

    Accepted Solution

    No, it is so insecure that it Shouldn't be done.  It would give everyone access to your database.

    You can use AJAX to get info from an ASP or PHP page and display it in an HTML page.  Here's some info on AJAX
    LVL 9

    Expert Comment

    Yes PowerEdgeTech, anything is technically "possible" but as far as whomever is asking you to do this is concerned the answer is no. If that person is you, then no.

    If your only concern is updating links "URL Structure", you can batch replace those links pretty painlessly in Dreamweaver or Useful File Utilities and rest easy at night knowing your data isn't out there in the open.

    did I say "Don't do it?"     ;)
    LVL 32

    Author Closing Comment

    Sorry for the delay ... crash course in AJAX (of course I had to search way beyond w3schools to get it to work) and we're in business.

    mk ... while I appreciate your taking the time to show me how not to do it, I would (as you would) never consider that a real option.  I know I can change the extensions easy enough, but it is not a matter of "easy" ... the job requirement was to not change them (unless absolutely necessary).  AJAX is the answer to my question.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
    The viewer will learn how to dynamically set the form action using jQuery.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now