SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    shauno7's Avatar
    Join Date
    Jul 2004
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question remote connection to database

    Hi,
    i encounter a problem on remotely connecting to a bd as i have two sites which i want to share the same db but they are both on different hosting servers. im assuming i have to use a remote connection to the db, so i would have to change the 'localhost' variable. but im not sure what to alter the 'localhost' variable with. could someone show me how a remote connection to a db is done.
    thanks,
    shaun

  2. #2
    Non-Member GlobalFusion's Avatar
    Join Date
    Jul 2004
    Location
    globalfusion.com.au Google PageRank: 5
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here you go:

    (This is in PHP btw)

    Just add this to a file called db.php and include it when you need it:
    PHP Code:
    @include('db.php'); 

    PHP Code:
    <?php

    //MYSQL Database Hostname
    $dbhost 'dbdomain.com'/*The Domain where your MYSWL Database is hosted*/

    //MYSQL Database User
    $dbuser 'me_user';/*Your MYSQL DB Username*/

    //MYSQL Database Password
    $dbpass 'password'/*Your MYSQL DB Password */

    //MYSQL Database Name
    $dbname 'pcentral_site'/*Your MYSQL DB Name*/


    /* Now Here is the ACTUAL Connection Strings using the above data */
    $db = @mysql_connect($dbhost$dbuser$dbpass)

        or die(
    'Failed to connect to db server.<br>MySQL error: '.mysql_error());



    @
    mysql_select_db($dbname)

        or die(
    'Failed to select db.<br>MySQL error: '.mysql_error());

    ?>
    Got any questions, either reply to this msg, or contact me on ICQ or MSN or EMAIL.

    Ciao.


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
  •