We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27449
    • 211 Posts
    Hi all...

    I need your help for to do a odbc conection....
    I have a database in the other server and I need to connect there, I try to do with the code below but without sucess.
    Please can you help me

    $link = mssql_connect("server", "root", "pass");
    if(!$link) {
    echo’Could not connect’;
    die(’Could not connect: ’ . mssql_error());
    }
    echo’Successful connection’;
    mssql_close($link);
      • 15083
      • 697 Posts
      //connect to seperate mysql db
      $modx->db->connect(’123.45.6.7’, ’mydb’, ’user’, ’password’, true);
      $res = $modx->db->select(’*’, ’this_table’);
      while($tmp = $modx->db->getRow($res, ’assoc’))
      {
      //do somethign with the data
      }
      //disconnect
      $modx->db->disconnect()

      //reconnect to modx db
      $modx->db->connect();

      Taken from here: http://wiki.modxcms.com/index.php/API:DBAPI:connect
        • 27449
        • 211 Posts
        I try but doesn’t work....
        the database is not mysql but sql.. it’ll be for this!?

        Your code return me this error:
        PHP error debug
        Error: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known.
        Error type/ Nr.: Warning - 2
        File: C:\wamp\www\real_estate\manager\includes\extenders\dbapi.mysql.class.inc.php
        Line: 89
        Line 89 source: if (!$this->conn = ($persist ? mysql_pconnect($host, $uid, $pwd) : mysql_connect($host, $uid, $pwd, true))) {
          • 15083
          • 697 Posts
          It’s an MS SQL DB?
          Is the database server on the same machine as the web server hosting your site?
            • 27449
            • 211 Posts
            yes, it’s an MS SQL DB.
            and the database is in a distinct host of my website
              • 15083
              • 697 Posts
              The code you are using should have worked then.

              $myServer = "localhost";
              $myUser = "your_name";
              $myPass = "your_password";
              $myDB = "examples";

              //connection to the database
              $dbhandle = mssql_connect($myServer, $myUser, $myPass)
              or die("Couldn’t connect to SQL Server on $myServer");

              //select a database to work with
              $selected = mssql_select_db($myDB, $dbhandle)
              or die("Couldn’t open database $myDB");

              Do you get an error when u use this code?