Remotely Accessing MYSQL database via PHP

Discussion in 'MySQL' started by mehbooba, Sep 29, 2006.

  1. #1
    can someone help me please. I have my php scripts on one server (server A) with one host and my MYSQL database hosted on another server (server B)with another different host.

    now i'm attempting to connect to a MYSQL database on server B via a php script from server A. Here is the PHP script :


    <?

    $siteemail='admin@serverA.com';
    $subject="SQL Database Down";
    $message="SQL Database Down\nError Number=";

    $headers = 'From: ' . "\r\n" . 'Reply-To: ' . "\r\n" . 'X-Mailer: PHP/' . phpversion();



    $link=mysql_connect("mysql1.serverB.net:3306","ServerB_user","PWD");
    $error = mysql_errno();

    if (!$link)
    {
    echo "Mysql connect error = $error";

    $message .= $error;
    mail($siteemail,$subject,$message,$headers);
    exit;
    }

    else

    {
    $db_selected = mysql_select_db ("Server_DB");
    $error = mysql_errno();

    if (!$db_selected)
    { echo "Mysql select db error = $error";

    $message .= $error;
    mail($siteemail,$subject,$message,$headers);
    exit;
    }

    }


    ?>



    it reaches :

    $link=mysql_connect("mysql1.serverB.net:3306","ServerB_user","PWD");

    and tries to connect and exits with this being printed on the screen :

    Mysql connect error = 2003


    It doesnt reach the mysql_select_db command.


    What am i doing wrong ? Why cant i connect ?

    thanks in advance.
     
    mehbooba, Sep 29, 2006 IP
  2. Mystique

    Mystique Well-Known Member

    Messages:
    2,579
    Likes Received:
    94
    Best Answers:
    2
    Trophy Points:
    195
    #2
    You cannot connect to a MySql database hosted elsewhere, disregard you own both accounts.

    Most hosting services have disable that option due to abuse and security breaches, so you can only connect to your localhost, not a remote database, unless you get one from those services that offer such facility :rolleyes:
     
    Mystique, Sep 29, 2006 IP
  3. mehbooba

    mehbooba Peon

    Messages:
    260
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    mystique

    thanks for that... can you give me some hosters that allow remote access to their mysql databases ?

    tia
     
    mehbooba, Sep 29, 2006 IP
  4. Mystique

    Mystique Well-Known Member

    Messages:
    2,579
    Likes Received:
    94
    Best Answers:
    2
    Trophy Points:
    195
    #4
    Sure Tia, this is a good site that only asks for a link back in your main page to give your remote access to your mysql database hosted with them: www.free-mysql.bizhostnet.com
     
    Mystique, Sep 29, 2006 IP
  5. mehbooba

    mehbooba Peon

    Messages:
    260
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    many thanks.. appreciated

    by the way how much space do they give you ?
     
    mehbooba, Sep 29, 2006 IP