Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Posts
    5

    Post Unanswered: Connection PHP & MYSQL with different servers

    I currently have 2 servers. My web server and my mysql server. My webpage is php and i want to connect to my mysql server. How do I establish the connection in the code? Any help is good, heres the code i use now for them both locally on the same machine, but i want to separte them.

    <?php // db.php

    $dbhost = "------";
    $dbuser = "------";
    $dbpass = "------";

    function dbConnect($db="------") {
    global $dbhost, $dbuser, $dbpass;

    $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
    or die("The site database appears to be down.");

    if ($db!="patientcredit" and !@mysql_select_db($db))
    die("The site database is unavailable.");

    return $dbcnx;
    }
    ?>

  2. #2
    Join Date
    Feb 2002
    Location
    North Wales, UK
    Posts
    114
    To connect to mysql that is running on the same machine that the web server is you would specify
    PHP Code:
    $dbhost "localhost"
    To connect to a remote mysql server change this to the servers hostname
    PHP Code:
    $dbhost "domain.com"
    J^ - web | email
    newsASP Developer

  3. #3
    Join Date
    Jul 2003
    Location
    TURKEY
    Posts
    2
    <?php // db.php

    $dbhost = "domain.com";
    $dbuser = "------";
    $dbpass = "------";

    function dbConnect($db="------") {
    global $dbhost, $dbuser, $dbpass;

    $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
    or die("The site database appears to be down.");

    if ($db!="patientcredit" and !@mysql_select_db($db))
    die("The site database is unavailable.");

    return $dbcnx;
    }
    ?>

Posting Permissions

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