Skip to main content
Inspiring
November 3, 2010
Question

database username/password

  • November 3, 2010
  • 1 reply
  • 2310 views

Hi,

I have a website and am using coldfusion and  dreamweaver.  My hosting service requires that, in order to access the  database, you must define a username and password in the code.  Its  working online, but in order to get it working on my localhost I have to  delete the username and password from the code.  Is there some way I  can make my localhost need to access the database with the same username  and password my hosting service requires?  It's a pain having to work  on a page and constantly switch between no username and password to a  defined username and password in the code.

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    November 3, 2010

    Set the user/pass as a global variable (application scope should be fine)

    and use cfif statement in application.cfc or application.cfm to check if you

    are using local host or live site. Then set the variable to the right

    datasource name, user and pass.

    tclaremont
    Inspiring
    November 3, 2010

    You could modify the dsn on your local installation so that it DOES require a username and password.

    wycksAuthor
    Inspiring
    November 4, 2010

    sorry, but I don't know what DSN is... can you give me a little explanation?  And where would I have to go/what would I have to do to change it so it DOES require a username and password every time?  In the coldfusion administrator?  In the coldfusion administrator, It looks like my database  defaults to username: root and password: [blank].  I think I tried changing those to the username and password that my site has for my hosting service, but I don't think that worked.  Should it have worked?  I do want to make it so it does require a password.

    I would also like to try using application.cfc and do the cfif statement in it, but the way I have my code, it wants to ask for the username and password every time it wants to access the database. that's why I'd like to just have the username and password required on my localhost as well as my hosting service... because i'm not sure how to do the cfif statement in application.cfc because each page requires something like the bit of my code below.  (I would still prefer to just have the localhost require the same username and password for accessing the database, though)

    <cfquery name="rsBookReview" datasource="mymindsnotrighttest" username="mikewycklendt" password="password">
    SELECT *
    FROM books
    WHERE book_id = <cfqueryparam value="#URL.book_id#" cfsqltype="cf_sql_numeric">
    </cfquery>
    <cfquery name="Recordset1" datasource="mymindsnotrighttest" username="mikewycklendt" password="password">
    SELECT *
    FROM book_comments
    WHERE book_id = <cfqueryparam value="#URL.book_id#" cfsqltype="cf_sql_numeric">
    ORDER BY book_comment_id ASC
    </cfquery>
    <cfquery name="Recordset2" datasource="mymindsnotrighttest" username="mikewycklendt" password="password">
    SELECT *
    FROM book_comments
    WHERE book_id = <cfqueryparam value="#URL.book_id#" cfsqltype="cf_sql_numeric">
    ORDER BY book_comment_id ASC
    </cfquery>