Topic: CF equivalent DB connection


GrowlyBear    -- 08-01-2008 @ 6:24 AM
  Hi all, in PHP they have this simple code:

<?php
$link = mysql_connect('<server>', '<username>', '<password>');
if (!$link) {
  die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
?>


Check if your username,password,server is correct or else it gives an error.

It can do this even if NO db/table have been created.
So what? You can use this to make an app that can "setup" itself with minimal effort on your side.

AND/OR do a test to see if the db connection is up so it can redirect you to an error page instead of you seeing a messed up page.

Does anyone know of the equivalent in CF?

~~~~~~~~~~~~~~~~~~~
CF PaperClip
http://www.cfpaperclip.com
CF & OOP in baby steps.


louissto56    -- 08-01-2008 @ 10:27 AM
  <cfquery>

In CF you have a thinkg called datasources that is like a continuos connection that you dont have to connect every time.

Louis

-----------------------------
www.MyBizList.com.au - QLD Business Directory and rent-a-site


GrowlyBear    -- 08-01-2008 @ 10:35 AM
  Buddy give me a working example.
Please note it must do the same as the php example.


~~~~~~~~~~~~~~~~~~~
CF PaperClip
http://www.cfpaperclip.com
CF & OOP in baby steps.


tmbrown    -- 08-04-2008 @ 2:27 PM
 

<?php
$link = mysql_connect('<server>
', '<username>', '<password>');
if (!$link) {
  die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
?>


To


<cfquery name="link" datasource="ODBC/JDBC Connection">
    SQL Here
</cfquery>
    <cfif link.RecordCount GT 0>
        Connected Successfully!
    </cfif>


You have to setup a DSN using the ColdFusion admin panel.  If the connection is unsuccessful, ColdFusion will shoot up an error automatically.

T-Rav


GrowlyBear    -- 08-04-2008 @ 3:50 PM
  thanks tmbrown for the idea

But I had already tried something similar to your solution before I asked.

I was just hoping there was another way.

~~~~~~~~~~~~~~~~~~~
CF PaperClip
http://www.cfpaperclip.com
CF & OOP in baby steps.


EasyCFM.COM ColdFusion Forums : http://archive.easycfm.com/forums
Topic: http://archive.easycfm.com/forums/viewmessages.cfm?Forum=27&Topic=13620