SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Israel
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem connecting to db

    I have a existing php program that works.
    it connects to a db named db1 that I can see and change from phpmyadmin.

    The strange thing is the connection file points to a db called maindb even though when I do changes in db1 it shows.
    I now want to change it to db2 and I don't know where to change it.

    here is my code -- can someone advise me where this is connecting

    <?php

    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_db = "localhost";
    $database_db = "maindb";

    $username_db = "myusername";

    $password_db = "mypassowrd";
    $db = mysql_pconnect($hostname_db, $username_db, $password_db) or die(mysql_error());
    mysql_select_db($database_db, $db);


    ?>

  2. #2
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Canada
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the code your displaying above is the contents of an include file called Connection_php_mysql.htm, then you'll want to rename it to something like connection.inc.php. Now if your script requires that you connect to a couple of other databases, then perhaps you'll want to create a couple of other include files and call them db1.inc.php and db2.inc.php so you can call on them anytime you need to connect to a different database.

    The only thing you'll need to change in the file is the following:
    For include file for db1:
    $database_db = "db1";
    $username_db = "db1username";
    $password_db = "db1passowrd";

    For include file for db2:
    $database_db = "db2";
    $username_db = "db2username";
    $password_db = "db2passowrd";

    Then call on them when you need to connect to a particular database. You might consider closing the connection to one database before opening another.

    I hope I've understood you correctly, therefore I hope this helps. Not really sure what you're asking, but those are the basics laid out for you. You can connect to any database at anytime as long as the information is correct.

    Paul

  3. #3
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Israel
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually it's .php not .htm
    and i basically copied the code into a different subdirectory and set up a different db and want to connect to a different db from in the other subdirectory.
    not connected to the other db

    it still doesn't work with the new db -- it's very strange

  4. #4
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Canada
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you getting an error message?

    Do you have the proper permissions set for the connecting user in the MySQL database?

    Of course you need the correct DB name.

    Hmm...Looking forward to reading any error messages.

    Paul

  5. #5
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Israel
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no error messages

    i'm using the same username and password as teh first db and it works fine.

  6. #6
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    offtopic : Why would you store your database detials in a htm file. Any body can open this file and can look at your database details. renmae it to .php just to be on safe side. of put them outside your web root.
    my 2 cents
    ---------------------------
    Errors = Improved Programming.
    My Site

  7. #7
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Israel
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not an html file.

    I managed to get it going by putting a new login and password

  8. #8
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Canada
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to hear it. So it was a username and password mix up.

    Paul

  9. #9
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •