EasyCFM.COM ColdFusion Forums / PHP to CFML / CF equivalent DB connection

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: CF equivalent DB connection

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

GrowlyBear
08-01-2008 @ 6:24 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1314
Joined: May 2004

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
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1149
Joined: Jan 2007

<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
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1314
Joined: May 2004

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
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 143
Joined: Aug 2007


<?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
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1314
Joined: May 2004

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.


Website Designed and Developed by Pablo Varando.