i'm looking to find out how to query a database and output XML. I've seen it done hard coded but i was wondering if there was any way to do it like the code below. It is in ASP I'm now migrating to PHP though.
I'm sure there is a way to do it this way, but haven't been able to find any examples.
<%@ Language=VBScript %>
<%
vendorType = Request.QueryString("vendorType")
vendorState = Request.QueryString("vendorState")
s=chr(10)
Set cn = Server.CreateObject ("ADODB.Connection")
'cn.ConnectionString = "pycDB2"
cn.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=" & Left(Request.ServerVariables("PATH_TRANSLATED"),InStrRev(Request.ServerVariables("PATH_TRANSLATED"), "\")) & "login.mdb"
Set cmd = Server. CreateObject ("ADODB.Command")
cmd.ActiveConnection = cn
cmd.CommandType = 1
cmd.CommandText = "SELECT * FROM tblVendors WHERE Vendor_state='" & vendorState & "' and Vendor_type ='" & vendorType & "' ORDER BY Vendor_name"
Set rs = cmd.Execute
Set objXML = Server.CreateObject("MSXML.DOMDocument")
Set elm = objXML.createElement("calander")
objXML.appendChild elm
Do Until rs.EOF
Set elm = objXML.createElement("events")
elm.setAttribute "where", rs("Vendor_name")
elm.setAttribute "genre", rs("Vendor_shortDisc")
elm.setAttribute "address", rs("Vendor_address")
elm.setAttribute "city", rs("Vendor_city")
elm.setAttribute "state", rs("Vendor_state")
elm.setAttribute "discount", rs("Vendor_discount")
objXML.firstChild.appendChild elm
rs.MoveNext
Loop
Response.Write ("<?xml version=""1.0"" encoding=""UTF-8""?>" & objXML.xml)
%>