Está en la página 1de 19

http://www.quackit.com/coldfusion/tutorial/coldfusion_database_queries.cfm ColdFusion Tutorial This ColdFusion Tutorial is for beginners.

It teaches you ColdFusion from the ground up - starting with the basics. This tutorial assumes you are comfortable coding HTML. If you aren't comfortable with HTML, start with the HTML Tutorial first, then return to this page to learn ColdFusion! Table of Contents The tutorial consists of the following lessons: Advanced ColdFusion ColdFusion Mail Basic ColdFusion ColdFusion Functions Introduction ColdFusion Components ColdFusion Installation ColdFusion Web Services ColdFusion Editors ColdFusion Upload File ColdFusion Syntax ColdFusion Read File ColdFusion Includes ColdFusion Write File ColdFusion Variables ColdFusion Append File ColdFusion Variable Types ColdFusion Rename File ColdFusion If Statements ColdFusion Copy File ColdFusion Loops ColdFusion Move File ColdFusion Datasource ColdFusion Delete File ColdFusion Database Queries Cffile Parameters ColdFusion Lists Using cffile Parameters ColdFusion Arrays ColdFusion FTP ColdFusion Redirect cfftp Cached Connections ColdFusion Debugging ColdFusion HTTP (cfhttp) ColdFusion Error Handling ColdFusion Query of Queries ColdFusion Charts ColdFusion Summary What Is ColdFusion? ColdFusion is one of the easiest programming environments to use, and enables you to create powerful server-side web applications very quickly, with much less code than other technologies such as ASP, PHP etc. ColdFusion integrates many Internet technologies such as XML, Java, web services etc, and as such, your applications can be as small or complex as required. ColdFusion consists of two main elements: A ColdFusion server (which runs on top of your web server), ColdFusion templates (or files), which you write using ColdFusion Markup Language (CFML). That's probably a very simplistic way of putting it, as there are many elements that make up a ColdFusion environment, but these two are essential if you want to build a ColdFusion application/website. What Can ColdFusion Do? ColdFusion enables you to build large, complex, and dynamic websites. ColdFusion can also increase your productivity enormously, both in development time and maintenance time. With ColdFusion, you can build websites that do things such as: Query a database Allow users to upload files Create/read files on the server (for example, the files that your users upload) Have a "member's area" (i.e. via a login page) Have a shopping cart Present a customized experience (for example, based on users' browsing history) Create a "member's area" (i.e. via a login page) Send emails (for example, newsletters to a mailing list) Schedule tasks to run automatically (for example, your email newsletters)

FTP files to/from another server Publish web services Much, much more OK, I'm Sold. How Do I Get Started? To build ColdFusion applications, you first need to install the ColdFusion server. Don't worry if that sounds like too much work - it's very straight forward. Installing ColdFusion is just like installing any other piece of software - you simply click your way through the installation wizard, configuring it as you go. This tutorial will point you in the right direction. Once you've installed ColdFusion server, you can write code using the ColdFusion Markup Language (CFML). CFML uses a syntax that closely resembles HTML and XML. This makes it easy to learn if you're familiar with HTML or XML. CFML however, is more powerful than HTML - it is basically a programming language. You can write conditional statements, loops, query a database, send bulk emails, publish web services and much more. ColdFusion also provides an administration interface (the ColdFusion Administrator), which enables you to customize your ColdFusion environment. As mentioned in the introduction, you need to install ColdFusion before you can build ColdFusion applications on your local computer. You can install ColdFusion from disk or download it from the Adobe website (Adobe is the company that produces ColdFusion). ColdFusion (at the time of writing) comes in two editions: Standard and Enterprise. There are also two free editions: Trial and Developer. The Developer edition is based on the Enterprise version but is limited to running on localhost and two other machines. The Adobe website has a comparison of the ColdFusion editions. Don't forget that the (free) developer edition actually gives you the same functionality as the full-blown enterprise version. The only limitation is that you can only access the website from the local computer and two other IP addresses. This means that, as long as your web hosting company supports ColdFusion, you don't actually need to pay for ColdFusion in order to build your website. Screen Shots of Installation To give you an idea of what ColdFusion installation involves, below are the steps that I took when installing ColdFusion 8 Developer edition onto a machine running Windows XP. Initial Screen: Confirm Language Once you've downloaded ColdFusion , double click on the icon. This should launch the following window. Click "OK" to confirm that the language is correct. If it's not correct, either select the correct language (if you can) or head back to the Adobe website and download the correct file.

Step 1: Introduction Once you've confirmed the language, the ColdFusion installation process begins. As you can see from the following screen shot, this is a 7 step process (although, it may be more, depending on the options that you select).

Step 2: Licence Agreement Confirm that you've read and agree to the licence agreement:

Step 3: Install Type Select the installation type. In most cases, selecting "Developer Edition" is fine. Only select "30 Day Trial" if you need to be able to access your website from more than 2 external IP addresses (in addition to the website's local computer). Once the 30 days is up, ColdFusion will revert to the Developer edition (unless you pay for the Standard or Enterprise version). Of course, if you have purchased a copy of ColdFusion, enter your serial number at this screen.

Step 4: Installer Configuration Select an installer option. The first option ("Server Configuration") is the most common option. The other options are useful for running multiple instances of ColdFusion on your computer. If you choose the second or third option, you should refer to the ColdFusion documentation.

Step 5: Subcomponent Installation Select the subcomponents you want to install. By default, all subcomponents are selected.

Step 6: Select Installation Directory Select the directory you'd like to install Coldfusion into:

Step 7: Licence Agreement (for Adobe LifeCycle Data Services ES) This screen only appears if you previously selected Adobe LifeCycle Data Services ES (at step 5):

Step 8: Adobe LifeCycle Data Services ES Installation This screen only appears if you previously selected Adobe LifeCycle Data Services ES (at step 5). If you have a serial number for Adobe LifeCycle Data Services ES, enter it here. Otherwise leave it blank:

Step 9: Previous ColdFusion Installation Detected This screen may be different, depending on whether your computer has a previous version of ColdFusion installed. If you do, you can choose to have both versions co-exist on your computer, or to overwrite the previous version. In this example, I chose to configure my web server (IIS) to use the new version. Doing this overwrites the previous version:

Step 10: Configure Web Servers/Websites If you run your own web server (such as IIS or Apache), this screen allows you to select which websites should be configured to use ColdFusion:

Step 11: Choose ColdFusion Administrator Location This screen lets you choose where to put the files for the ColdFusion Administrator. The CF Administrator is usually accessed via /cfide/administrator: I sometimes like to keep these files separate to the rest of the website. Therefore, I use a separate location at this screen. I then create a virtual directory (from my web server ) and map it to this directory. Creating the virtual director allows me to access the ColdFusion Administrator from http:// {webroot}/cfide/administrator".

Step 12: Administrator Password You are required to enter a password which is used for accessing the ColdFusion Administrator:

Step 13: Enable RDS You have the option of enabling RDS (Remote Development Service). Only enable RDS if you need to access the server remotely for development purposes. As a general rule, you should disable RDS on production servers (for security reasons).

Step 14: Pre-Installation Summary Review your settings. You can go back and change anything that's incorrect. If all is correct, click "Install". This is the bit that actually installs ColdFusion on your computer.

Step 15: Installation Complete Once ColdFusion has been installed, you will see the following screen. You will be notified of any errors that occurred during installation with instructions on how to view the log file. It could take around 5 to 10 minutes for installation to complete, and for this screen to appear.

ColdFusion Migration Once ColdFusion has been installed, open the ColdFusion Administrator at http:// {websiteroot}/cfide/administrator (where {websiteroot} is the URL of your website). If your ColdFusion installation was upgraded from a previous ColdFusion installation, you will be prompted through a migration wizard. This will automatically migrate your previous ColdFusion settings to your new installation. Here are some screen shots of the ColdFusion Migration Wizard. ColdFusion 8 Migration Wizard This article shows you screen shots of ColdFusion Migration Wizard. The ColdFusion Migration Wizard is used when you have upgraded your ColdFusion installation to a new version. The following screen shots were taken when I upgraded from ColdFusion 6.1 to ColdFusion 8. Once ColdFusion has been installed, open the ColdFusion Administrator at http:// {websiteroot}/cfide/administrator (where {websiteroot} is the URL of your website). If your ColdFusion installation was upgrading from a previous ColdFusion installation, you will be prompted through a migration wizard. This will automatically migrate your previous ColdFusion settings to your new installation. Screen Shots When you first open the ColdFusion Administrator, you will be prompted for your password. This is the password you specified during the ColdFusion Installation process. Once logged in, proceed through the wizard. Configuring Server This can take several minutes. Just wait patiently :)

Migration This migrates existing settings and resources, including data sources, custom tags, and Verity collections.

Export Settings (from previous installation) This step exports the settings from the previous installation.

Import Settings (to new installation) This step imports the settings to the new installation.

Migration Complete This step simply informs you that the migration is complete. When you click "OK", the ColdFusion Administrator will be displayed.

That's all there is to it! To learn more about installing ColdFusion, see ColdFusion Installation. ColdFusion Syntax The term ColdFusion Syntax refers to a set of rules that determine how the ColdFusion application will be written by the programmer, and interpreted by the ColdFusion Server. These rules are referred to as the ColdFusion Markup Language (CFML). CFML is, as the name would suggest, a markup language that programmers need to use when they create a ColdFusion application. It consists of a number of tags. Similar to HTML, these usually consists of an opening tag and a closing tag, and are surrounded by greater than and less than symbols. Closing tags have a forward slash after the less than symbol. ColdFusion tags can also contain one or more attributes. Tag Syntax ColdFusion tags use the following format. <tagname attribute="value"> Code/text that is affected by the surrounding tags. </tagname> Code Example ColdFusion code: <cfoutput query="myQuery"> #firstname#<br />. </cfoutput> ColdFusion Includes (cfinclude) If you've used other scripting environments such as ASP or even .shtml files, you would be familiar with the concept of "includes". An "include" is a file that is embedded, or "included" within another file. This can be very useful when you want multiple ColdFusion templates to share the same block of code. A typical example might be your website's header and footer. If your website has a consistent header and footer on every page, you could use an include file for each of these. ColdFusion provides the cfinclude tag for specifying included files. Tag Syntax You'll notice that the cfinclude tag doesn't have a closing tag - it just accepts an attribute value (the included filename). <cfinclude template="included_filename"> Code Example A common use of ColdFusion includes is to output a consistent header and footer throughout each page of a website. In this example, we're going to create a basic ColdFusion template which uses the cfinclude tag to include two other files. File 1: index.cfm <cfinclude template="header.cfm"> <p>Welcome to my website on ColdFusion cfinclude usage!</p> <cfinclude template="footer.cfm"> File 2: header.cfm <h1>This is the header</h1> File 3: footer.cfm <h1>This is the footer</h1>

Once you've created all of the above files, open index.cfm in your browser. The page should contain the contents of header.cfm at the top, and footer.cfm at the bottom. Now create a fourth ColdFusion template as follows and open it in your browser. File 4: about.cfm <cfinclude template="header.cfm"> <p>Who are we? We are ColdFusion cfinclude enthusiasts of course!</p> <cfinclude template="footer.cfm"> Because this template includes the same header and footer file, you will see the same header and footer when displayed in a browser. ColdFusion Variables Variables are a standard part of any programming language. A variable can be visualised as a container that stores a value. We can use variables in many circumstances. For example, we could store the user's name inside a variable. We could then present the user's on the web page they're visiting. We could also perform a test against the variable to see what the value is. The application could then perform a different action depending on the value of the variable. Using cfset Syntax To set a ColdFusion variable, use the cfset tag. To output the variable, you need to surround the variable name with hash (#) symbols and enclose it within cfoutput tags. <cfset variablename="value"> <cfoutput> #variablename# </cfoutput> Example of Usage This example uses the cfset tag to declare a variable called "firstname" and assign a value of "bono" to it. It then outputs the contents of the variable. ColdFusion code: <cfset firstname="Bono"> <cfoutput> Hello #firstname#. </cfoutput> Display in browser: Hello Bono. Using cfparam The cfparam tag creates a variable if it doesn't already exist. You can assign a default value using the default attribute. This can be handy if you want to create a variable, but don't want to overwrite it if it has already been created elsewhere. Example 1 In this example, the variable hasn't been set previously, so it will be assigned with the cfparam tag. <cfparam name="firstName" default="Ozzy"> <cfoutput> Hello #firstName# </cfoutput> This results in the following: Hello Ozzy Example 2 In this example, the variable has already been assigned (using the cfset tag), so this value will override the default value in the cfparam tag. <cfset firstname="Barney"> <cfparam name="firstName" default="Ozzy"> <cfoutput> Hello #firstName# </cfoutput> This results in the following: Hello Barney

Checking if a Variable Exists You can check if a variable has been defined or not by using ColdFusion's built in IsDefined() function. This can be used inside a cfif tag to prevent nasty error messages in the event you attempt to refer to a variable that doesn't exists. You could also use this function to determine whether a user has performed a certain action or not. <cfif IsDefined("firstName")> Hello #firstname#! <cfelse> Hello stranger! </cfif> ColdFusion Variable Types ColdFusion variables come in many different types. Firstly, all variables belong to a scope. There are many different scopes and each variable created in your application belongs to one of these scopes. Secondly, all variables can be either local or global. Thirdly, all variables are either persistent or non-persistent. Variable Scopes A variable's scope is determined by its origin. The scope determines a number of properties about the variable, such as its life span, timeout, and storage location, and therefore, how it can be used. Below is a list of the available scopes for ColdFusion variables: Scope Description This scope refers to local variables that are not specifically reserved for use in custom tags. If Variables you set a variable without specifying a scope (i.e. <cfset variableName = "">, it will automatically belong to the variables scope. This scope is used within a custom tag. When you pass an attribute to a custom tag, it Attributes becomes available in the custom tag within the attributes scope. Caller Used within a custom tag to set or read variables within the template that called it. Arguments Used within a function to refer to arguments that were passed in by the calling template. This Used within a component to store its own properties. The Request scope is used for the current request. These variables are non-persistent global Request variables. CGI variables describe the current requests environment, are created automatically, and are CGI read-only. You can't modify a CGI variable, only read it. Form Variables submitted from a form using the "Post" method become part of the Form scope. URL Variables passed through the URL are part of the URL scope. Server Server scope variables are available to all applications on the current server. Application scope variables are available to a whole application (as defined in the <cfapplication Application name=""... tag within the Application.cfm file). The Session scope is available for the life of a user's session. The length of the lifespan can be determined by a given period of inactivity. This period can be determined in the cfapplication Session tag. For example, to set a timeout after 20 minutes of inactivity: <cfapplication ... sessiontimeout = "#CreateTimeSpan(0,0,20,0)#" Client variables are stored on the server, either in the registry or a database (but can also be Client stored in a cookie on the client machine). Cookie Cookie variables are global, and persistent, variables stored on the user's machine. "Scoping" your Variables When you set or read a variable, it is good practice to tell ColdFusion which scope it belongs to. Although this is not required, it will avoid any confusion around whether the correct variable is being used or not. You may occasionally encounter two or more variables with the same name, but belonging to a different scope. To avoid the wrong one being used, you should scope your variables. You scope a variable simply by prefixing the variable name with the name of the scope (and separating them with a dot). <cfset scope.variablename="value"> <cfoutput> #scope.variablename# </cfoutput> For example, to scope a session variable, you would do something like this: <cfset Session.BodyType = "Perfect">

<cfoutput> Body Type: #Session.BodyType# </cfoutput> Variable Persistence The following chart outlines the different variable scopes, whether they're local or global, and indicates whether they are persistent variables or non-persistent. Non-Persistent Persistent Variables Attributes Local Variables (none) Caller Arguments This Server Request Application CGI Global Variables Session Form Client URL Cookie ColdFusion If Statements As a programmer, you will often need to use conditional statements. A conditional statement is a piece of code that does one thing based on one condition, and another based on another condition. In fact, you could have as many conditions as you like. ColdFusion If statements are an example of conditional statements. With If statements, you can tell the ColdFusion server to execute a piece of code only if a given condition is true. Example If Statement In this example, the text "Still haven't found what I'm looking for." only gets displayed if the condition is met (that the value of the variable "firstName" equals "Bono". The letters eq are used with cfif to test that a something is equal to something. <cfset firstName = "Bono"> <cfif firstName eq "Bono"> Still haven't found what I'm looking for. </cfif> Display in browser: Still haven't found what I'm looking for. "If Else" Statement You can use the cfelse tag to do something if the condition is not met. <cfset firstName = "Ozzy"> <cfif firstName eq "Bono"> Still haven't found what I'm looking for. <cfelse> Choose your own song then... </cfif> Display in browser: Choose your own song then... Example "If Else If" Statement You can use the cfelseif tag to perform another test (only if the preceeding condition/s is/are not met). <cfset firstName = "Ozzy"> <cfif firstName eq "Bono"> Still haven't found what I'm looking for. <cfelseif firstName eq "Ozzy"> Crazy Train! <cfelse> Choose your own song then... </cfif> Display in browser: Crazy Train! NOT Equal To? Just as eq stands for equal to, neq stands for not equal to.

<cfset firstName = "Ozzy"> <cfif firstName neq "Bono"> Crazy Train! </cfif> Display in browser: Crazy Train! Less Than? You can use lt to test that a value is less than another. <cfset albumSales = 10> <cfif albumSales lt 100> Don't give up your day job! </cfif> Display in browser: Don't give up your day job! Greater Than? You can use gt to test that a value is greater than another. <cfset albumSales = 150000000> <cfif albumSales gt 1000000> Give up your day job! </cfif> Display in browser: Give up your day job! Greater Than Or Equal To/Less Than Or Equal To? You can use gte to test that a value is greater than or equal to another. You can use lte to test that a value is less than or equal to another. <cfset age = 80> <cfif age gte 80> Give up your day job! </cfif> Display in browser: Give up your day job! ColdFusion Loops (cfloop) A ColdFusion loop is a block of code that executes continuously either a secified number of times, once for each element in an object, or while a condition is true. In ColdFusion, you use the cfloop tag to perform a loop. The cfloop tag has a number of different attributes. The attributes used depends on the type of loop you're performing. Syntax <cfloop attribute1="" attribute2=""> Do something for each iteration of the loop. </cfloop> The Index Loop An index loop is a loop that continues for a specified number of times. You use the from and to attributes to specify how many iterations should occur. The index attribute holds the counter - it starts with the value of the to attribute and is incremented for each iteration of the loop (until it reaches the value of the from attribute). ColdFusion code: <cfloop from="1" to="5" index="i"> <cfoutput> #i#<br /> </cfoutput> </cfloop> Display in browser: 1 2 3 4 5 The (optional) step attribute allows you to determine how big the increments will be.

ColdFusion code: <cfloop from="1" to="10" index="i" step="2"> <cfoutput> #i#<br /> </cfoutput> </cfloop> Display in browser: 1 3 5 7 9 The Conditional Loop A conditional loop is a loop that executes while a condition is true. You use the condition attribute to specify the condtion to use. The following example uses a variable to determine whether to reiterate the loop or not. If the value of the variable is equal to false, the loop will continue to iterate. If it is set to true, it will exit the loop and continue the rest of the code. In this example, we use ColdFusion's RandRange() function to pick a random number between 1 and 10. If the number is 10, the myVar variable is set to true. ColdFusion code: <cfset myVar=false> <cfloop condition="myVar eq false"> <cfoutput> myVar = <b>#myVar#</b> (still in loop)<br /> </cfoutput> <cfif RandRange(1,10) eq 10> <cfset myVar="true"> </cfif> </cfloop> <cfoutput> myVar = <b>#myVar#</b> (loop has finished) </cfoutput> Display in browser: Tip: Refresh this page a few times and you should see the number of lines change (due to a different random number being generated within the loop). myVar = false (still in loop) myVar = false (still in loop) myVar = false (still in loop) myVar = false (still in loop) myVar = false (still in loop) myVar = false (still in loop) myVar = false (still in loop) myVar = true (loop has finished) The Query Loop You can loop over the results of a ColdFusion query (i.e. using the cfquery tag). Don't worry - if you don't know what I mean by that, we will be learning about ColdFusion queries soon. ColdFusion code: <cfquery name="getMovies" datasource="Entertainment"> select top 4 movieName from Movies </cfquery> <cfloop query="getMovies"> #movieName# </cfloop> Display in browser: Borat Crocodile Dundee

Lord of the Rings Last Samurai The List Loop You can loop over a list. You can use the (optional) "delimter" attribute to specify which characters are used as separators in the list. <cfloop list="ColdFusion,HTML;XML" index="ListItem" delimiters=",;"> <cfoutput> #ListItem#<br /> </cfoutput> </cfloop> Display in browser: ColdFusion HTML XML The File Loop You can loop over a file. To do this, you use the same attributes as you would for a list. <cfloop list="#myFile#" index="FileItem" delimiters="#chr(10)##chr(13)#"> <cfoutput> #FileItem#<br /> </cfoutput> </cfloop> COM Collection/Structure Loops You can loop over a Structure or COM collection. <cfset myBooks = StructNew()> <cfset myVariable = StructInsert(myBooks,"ColdFusion","ColdFusion MX Bible")> <cfset myVariable = StructInsert(myBooks,"HTML","HTML Visual QuickStart")> <cfset myVariable = StructInsert(myBooks,"XML","Inside XML")> <cfloop collection="#myBooks#" item="subject"> <cfoutput> <b>#subject#:</b> #StructFind(myBooks,subject)#<br /> </cfoutput> </cfloop> Display in browser: ColdFusion: ColdFusion MX Bible HTML: HTML Visual QuickStart XML: Inside XML ColdFusion Datasource ColdFusion is a great environment for connecting to, and performing queries against a database. Reasons for using a database could include authentication to a members' area, serving up content from a content management system, logging user feedback, and more. Any website that uses a database, needs a way to connect to the database and a way to query the database (i.e. using SQL Statements). Create a ColdFusion Datasource To allow ColdFusion to connect to a database, you first need to create a datasource. A datasource provides the connection between Coldfusion and the database. Another way of looking at it is that the datasource provides the link between your CFML code and the actual database. You create datasources via the ColdFusion Administrator. Follow the steps below to create a ColdFusion data source. 1. Log in to the ColdFusion Administrator (usually at http://{ website_url }/cfide/administrator) 2. Click on "Data Sources". You should see something like this:

3. Under "Add New Data Source", enter a data source name and driver type (i.e. Microsoft Access, or Microsoft SQL Server). The driver type will depend on your database type. 4. Click "Add" 5. Click "Show Advanced Settings" (optional) 6. Enter the details of your database. This screen should look something like this (although will differ depending on the driver you user):

7. Click "Submit"

Once you click submit, ColdFusion will verify the connection to the database. If there are any problems, you should check that the details you entered here match the details of the database (for example, usernames/passwords, server name etc). Now that you've created a datasource, you can now use the Datasource Name in your ColdFusion database queries. ColdFusion Database Queries (cfquery) In the previous lesson we created a datasource so that it could be used by ColdFusion to connect to a database. Now that we have the datasource, we can perform a query against the database that the datasource is linking to. To perform a database query in ColdFusion, you use the cfquery tag. Basic CFQUERY Example This code is all you need to do in order to query a database in ColdFusion. The cfquery tag connects to and opens the database for you, all you need to do is supply it with the name of the datasource. <cfquery datasource="Entertainment"> select * from Movies </cfquery> Authentication Many database configurations require authentication (in the form of a username and password) before you can query the database. You can supply these using the username and password attributes. Note that the username and password can also be configured against the datasource in the ColdFusion Administrator. Supplying these details in your query overrides the username and password in the ColdFusion Administrator. <cfquery datasource="Entertainment" username="webuser" password="letmein"> select * from Movies </cfquery> Cached Queries If you have a lot of traffic, you may find that performance of your website/application is affected. If so, you will need to look at ways of improving performance. One effective technique you can use is to cache some of your database queries. A cached query is a query that has its results stored in the server's memory. The results are stored when the query is first run. From then on, whenever that query is requested again, ColdFusion will retrieve the results from memory. For ColdFusion, it's much faster retrieving the results from memory than to perform another query from the database. When you query a database, ColdFusion has to wait whilst the database connection (often on another server) is established, the database is opened, the query is run, and the results are returned to ColdFusion. All this takes time, and it can impact on other ColdFusion requests occurring at the same time. You can cache a query using the cachedAfter attribute. If the query was last run after the supplied date, cached data is used. Otherwise the query is re-run. <cfquery datasource="Entertainment" cachedAfter="November 20, 2006"> select * from Movies </cfquery> You can also cache a query using the cachedWithin attribute in conjunction with the CreateTimeSpan function. In the following example, if the query's cached data is older than 1 hour, the query is re-run. Otherwise, cached data is used. <cfquery datasource="Entertainment" cachedwithin="#CreateTimeSpan(0,1,0,0)#"> select * from Movies </cfquery> Limiting the Number of Records Returned You can limit the number of rows to be returned by using the maxrows attribute. <cfquery datasource="Entertainment" maxrows="50"> select * from Movies

</cfquery> Timeouts You can set a timeout limit using the timeout attribute. This can be useful in preventing requests running far longer than they should and impacting on the whole application as a result. The timeout attribute sets the maximum number of seconds that each action of a query is allowed to execute before returning an error. <cfquery datasource="Entertainment" timeout="30"> select * from Movies </cfquery>

ColdFusion Editors ColdFusion can make creating website applications very easy, but your life will be made so much easier if you pick the right editor for editing your code. ColdFusion Builder Adobe ColdFusion Builder is your best bet for a ColdFusion editor. It is made by Adobe - the same company that produces ColdFusion. ColdFusion Builder provides a number of benefits over other editors including: Customizable keyboard shortcuts Smart tab assist Color coding to make your code easier to read Editors for CFML, CFScript, HTML, JavaScript, SQL, and CSS Integration with Flash Builder Free version of Flash Builder And much more You can download ColdFusion Builder for a 60 day trial. Once the trial expires, you need to purchase a license to continue using all the features. If not, ColdFusion Builder switches to a feature-limited Express Edition. So, even if you can't afford to pay for the full licence, you can still get a free ColdFusion editor, simply by downloading it. Plus, you will have had a sneak preview into the full-featured version. You can learn more about Coldfusion Builder from the ColdFusion section of the Adobe website. Dreamweaver You can use Adobe Dreamweaver as your ColdFusion editor too. As well as supporting ColdFusion, Dreamweaver supports many other web languages that you may need to code in. Here are some of Dreamweaver's features: Shortcuts to commonly tags and functions Color coding of HTML, CFML, ASP etc Wizards are provided for common tasks "Drag and drop" editing You can toggle between design view, code view, and split view Version control support Edit dialog for most HTML and CFML tags

Pop-up help for all HTML and CFML tags Automatic tag completion SQL query builder Expression builder Free ColdFusion Editors Editors such as ColdFusion Builder and Dreamweaver are fine if you're happy to pay money. If you don't want to pay that much for an editor you could try a basic HTML editor. Some HTML editors include ColdFusion support too. If you don't want to pay for an editor, you could try one of the following: ColdFusion Builder Express - remember, this is a stripped down version of ColdFusion Builder, and it's completely free. To get it for free, simply download it. You will get a 60 day trial of the fullfeatured version. Once this expires, you will have permanent use of the stripped down version. CFEclipse - this is a plugin for the Eclipse platform. First Page - HTML editor with ColdFusion support. ColdFusionPad - Like a simple text editor, but with menus for ColdFusion tags & functions. Includes code examples. You could download HTML Kit (HTML editor), then download and install one of the ColdFusion plugins such as dfCFMX. If you don't feel like downloading anything, don't despair! You can always use a text editor such as Notepad (for Windows) or SimpleText (Macs).

También podría gustarte