SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Linux MSSQL PHP Connection

    I am getting the following error trying to connect to a mssql express server from linux (mint16x32bit) to a windows 7 pc (firewall disabled atm)

    There was a problem. Caught exception: SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)
    I have tried combinations of the username, where have I gone wrong with this?

    Thanks in advance, James


    Connection String:

    Code:
    <?php
    
    	$msdbhost     = "192.168.1.10";
    	$msdbname     = "sqlCompanyTables";
    	$msdbuser     = "Jupiter\James"; 
    	$msdbpass     = "mypassword";
    
    try {
    	
    	// database connection
     	$msconn = new PDO("dblib:host=$msdbhost; dbname=$msdbname", $msdbuser, $msdbpass);
    	$msconn -> exec('SET CHARACTER SET utf8');
    		
    } catch(PDOException $e) {
    	echo 'There was a problem. Caught exception: ',  $e->getMessage(), "\n";
    }
    ?>
    Query:

    Code:
    <?php
    
    require "connection.php";
    
            $sql = "SELECT * FROM dbo.Projects_1";
    
        $sth = $msconn -> prepare($sql);
        $sth -> execute();
        $rows = $sth->fetchAll();       
    
           foreach ($rows as $row) {
    
            echo $row['City'] + '<br>';
           }
    
    ?>

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,625
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    2 things to look at -- first, IIRC using the mssql calls in PHP requires enabling / adding some extensions and perhaps some underlying libraries or drivers on linux. Second, did you enable remote connections on the server? Given it is win7 I'm presuming the express sku which typically comes with only local connections enabled; see http://stackoverflow.com/questions/1...r-express-2012 for some guidance on how to enable it.


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
  •