Advanced Search

Results 1 to 4 of 4

Thread: Connect to outside database?

  1. #1
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Question Connect to outside database?

    how do i connect to an outside database (not localhost)? database is on freehostia.com

    define("DB_SERVER", "mysql4.freehostia.com");
    define("DB_USER", "liaall_users");
    define("DB_PASS", "**********");
    define("DB_NAME", " liaall_users");
    Last edited by liamallan; 03-11-2010 at 04:45 PM.

  2. #2
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    Try this:
    PHP Code:
    <?php
        $connection 
    mysql_connect("mysql4.freehostia.com""username""password") or die(mysql_error());
        
    mysql_select_db("database_name"$connection) or die(mysql_error());
        
        
    // Rest of your script here.


       
    mysql_close($connection);
    ?>
    That usually work's, if it doesen't, then post the error info here (delete sensitive info of course). Then I or someone else can help you.

    Hope I helped.

    Edit: This is mysql_connect etc. using your defines
    PHP Code:
    <?php

        define
    ("DB_SERVER""mysql4.freehostia.com");
        
    define("DB_USER""liaall_users");
        
    define("DB_PASS""**********");
        
    define("DB_NAME"" liaall_users"); 

        
    $connection mysql_connect(DB_SERVERDB_USERDB_PASS) or die(mysql_error());
        
    mysql_select_db(DB_NAME$connection) or die(mysql_error());
        
        
    // Rest of your script here.


       
    mysql_close($connection);
    ?>

  3. #3
    Join Date
    Apr 2010
    Location
    UK
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Connect to outside database

    can you connect to database through command line with mysql command

  4. #4
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    Quote Originally Posted by akitodito View Post
    can you connect to database through command line with mysql command
    Yes, you can:

    Code:
    mysql -u DBUSER -h DBSERVERNAME -p
    Where:

    DBUSER = Your MySql Username. Usually: root
    DBSERVERNAME = The Location Of Your MySql server. Usually: localhost

    Assuming that you are using Windows.
    Last edited by hmsnacker123; 04-21-2010 at 04:01 PM.

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
  •