MySQL question, simple but I dont know

Discussion in 'MySQL' started by ludwig, Jul 3, 2006.

  1. #1
    Hi guys,

    Currently I am doing a site for a client, my friend is a PHP/MySQL programmer and I am an ASP/MsSQL programmer.

    Th hosting we have does not support MySQL databases, but we have a huge system setup on MySQL DB, we also have a huge system on an MsSQL DB. The MsSQl I know that you can have on separate server under a separate hosting and then in connection line specify the IP of the server and connect to it.

    Is it possible to connect to a MySQL DB which is on a separate server that the site. The hosting company is the same. Could you please write the connection string for me.

    With regards,
     
    ludwig, Jul 3, 2006 IP
    Crazy_Rob likes this.
  2. Boby

    Boby Peon

    Messages:
    207
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you mean to connect to MySQL from command line?
    mysql -h hostname -P 3036 -u username -D database -p
    Code (markup):
    -h (=hostname)
    -P (=port) uppercase "P"
    -u (=username)
    -D (=database)
    -p (=password) lowercase "p"

    If you want to connect through PHP to the MySQL DB, you can use:
    $link = mysql_connect('hostname', 'mysql_user', 'mysql_password');
    if (!$link) {
       die('Not connected : ' . mysql_error());
    }
    
    // make foo the current db
    $db_selected = mysql_select_db('foo', $link);
    if (!$db_selected) {
       die ("Can't use foo : " . mysql_error());
    }
    PHP:
    This is from php.net, I'm not allowed yet to post URLs.

    Boby
     
    Boby, Jul 3, 2006 IP
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, you can do remote connections but only if the host allows it. So the server with the MySQL DB on it needs to allow remote connections. It's in the config of MySQL.
     
    T0PS3O, Jul 3, 2006 IP
  4. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #4
    thank you guys, I have passed the note to my friend who does the PHP/MySQL thing

    see what happens
     
    ludwig, Jul 3, 2006 IP