Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Connect to MySql Database

    Hi
    I am hoping someone can point me in the right direction.
    I have changed my hosting package from a shared package to dedicated server and have been trying to reinstall the software that was developed for me using a new database.
    Previously the code to connect was
    Code:
    define( "DB_DSN", "mysql://dbo*****:PASSWORD@db****.oneandone.co.uk/db******");
    I changed the code to:
    Code:
    define( "DB_DSN", "mysql://dbo*****:PASSWORD@localhost:/tmp/mysql5.sock/db******");
    replacing the db****.oneandone.co.uk with localhost:/tmp/mysql5.sock as the new database is hosted on my dedicated server. Obviously I changed all the details as well. However it will not connect to the new database.

    I understand the define("DB_DSN string is causing errors and it has been recommended I use
    Code:
    define('DB_DSN', 'mysql/localhost:/tmp/mysql5.sock/db****');
    define('DB_USER', 'dbo**** ');
    define('DB_PASS', 'PASSWORD');
    but that also creates an error and somehting needs to changed with this part of the code as well - this is what I am stuck on:
    Code:
    function &db_connect() {
      $db_options = array(
        'debug'       => 2,
        'portability' => DB_PORTABILITY_ALL,
      );
      $db =& DB::connect(DB_DSN, $db_options);
      db_show_error($db);
    
      return $db;
    }
    // Connect to given dsn
    function &db_connectByDsn($dsn) {
      $db_options = array(
        'debug'       => 2,
        'portability' => DB_PORTABILITY_ALL,
      );
      $db =& DB::connect($dsn, $db_options);
      db_show_error($db);
    
      return $db;
    }
    Thanks for any help anyone can offer.
    Robbiez

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,246
    Thanks
    12
    Thanked 340 Times in 336 Posts
    judging from the DB docs, your DSN is wrong. if you have a common acces type, it should look like mysql://user:pass@localhost/database. check also the given examples, e.g. if you connect through a unix socket.


  •  

    Posting Permissions

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