Database Reference
In-Depth Information
ColdFusion identifies column names and variables within its tags by surrounding them
with hashes. So for each row in the query, the line above will output the user column value,
an @ sign, the host column value and a line break HTML tag. We then close the <CFOUT-
PUT> tag and complete the rest of the HTML page:
</CFOUTPUT>
</BODY>
</HTML>
As this is a lot easier to follow than the ASP example, due to the simplicity of the tags, we
will re-write the template so that the output is tabulated better. This template will then read
as follows:
<HTML>
<TITLE>Testing MySQL ODBC Table</TITLE>
<BODY>
<CFQUERY name=”getusers” datasource=”MyTestDataSource”>
SELECT *
FROM user
</CFQUERY>
<TABLE>
<TR><TD>Username</TD><TD>Host</TD></TR>
<CFOUTPUT query=”getusers”>
<TR><TD>#USER#</TD><TD>#HOST#</TD></TR>
</CFOUTPUT>
<TABLE>
</BODY>
</HTML>
The results of the above are shown in Figure 14.15. You will notice how, as when we
looked at ASP, we created the HTML outside of the loop, and then looped through each row
of the table using the CFOUTPUT associated with the query.
In summary, to connect and use MyODBC data within ColdFusion you:
Send the SQL query to the data source by wrapping it in a <CFQUERY> tag which you
name.
Use the results by wrapping the column names you wish to use in hashes, and using
these names and other HTML tags within a <CFOUTPUT> tag that refers to the query
name.
As with ASP, this demonstration can be used to connect ColdFusion to a MyODBC data
source on its server, or to any other ODBC data source that is available. It is not MyODBC
specific.
Search WWH ::




Custom Search