| Cold
Fusion and database interaction very often go hand-in-hand. Cold Fusion
can work with any ODBC compliant database as long as it has been converted
into the MySQL environment. For step-by-step instructions in making
the conversion please review: Using ODBC
Once you have a MySQL database set-up you need to make sure that
you use a database connection string in the body of the cfm file. The
example .cfm file from the previous page:
<cfquery datasource="database" password="db-password" username="db-username" name="products">
SELECT id, name, price
FROM products
ORDER BY id
</cfquery>
<html>
<head>
<title>Products List</title>
</head>
<body>
<table cellpadding=5>
<tr bgcolor="788C78">
<td>Item ID</td><td>Name</td><td>Price</td>
</tr>
<cfoutput query="products">
<TR bgcolor="CCCC99"><TD align="center">#id#</td><TD>#name#</td><TD>#price#</td></tr>
</cfoutput>
</table>
</body>
</html>
|
 |
The first line shows the connection string and the variables needed to interact with the database successfully:
<cfquery datasource="database" password="db-password" username="db-username" name="products">
Where:
"datasource" is the name of the MySQL database
"password" is the password for the database
"username" is the username for the database
"name" is the name of the table from which data is being used/presented
This string and the SQL instructions/requests must be enclosed inside of the
<cfquery></cfquery>
tags as in the example above, shown again here:
<cfquery datasource="database" password="db-password" username="db-username" name="products">
SELECT id, name, price
FROM products
ORDER BY id
</cfquery>
For more information on Cold Fusion please review: Cold Fusion Resources
|