1

Im having real trouble getting this to work. I have got the mssql-connect drivers set up and working on the Linux server, it now understands that function and does not return any errors.

I have had our server management team configure the windows server to allow the connection from the linux server. They have tested this and confirm it is all working, however I just cant seem to connect to it with PHP.

I have tried various connection strings, but it won't connect, here is an example

<?php
// Server in the this format: <computer>\<instance name> or 
// <server>,<port> when using a non default port number
$server = '214.133.182.71,1443';

// Connect to MSSQL
$link = mssql_connect($server, '****', '******');

if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
?>

I always get: Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: 214.133.182.71,1443 in /home/v3rec/public_html/test.php on line 10 Something went wrong while connecting to MSSQL

The username and password of that for the MS SQL database. Ive tried it with and without the port name. I am running SQL 2012, im not sure what the instance name would be? Am I missing something? Why is PHP unable to connect?

3
  • Instead of printing "Something went wrong", try doing: print_r(error_get_last()); die;. Commented Sep 3, 2015 at 15:59
  • Didnt give me any more into other than cant connect :( Commented Sep 3, 2015 at 16:06
  • Not sure if this will fix it, but try this: $server = '214.133.182.71:1443'; Commented Sep 3, 2015 at 16:15

1 Answer 1

3

May I suggest you use PDO and do this:

$dbhost  = "myhost";
$dbport  = 10060;
$dbname  = "tempdb";
$dbuser  = "dbuser";
$dbpass  = "password";
try {
    $dbh = new PDO ("dlib:host=$dbhost:$dbport;dbname=$dbname","$dbuser","$dbpass");
} catch (PDOException $e) {
    echo "Failed to get DB handle: " . $e->getMessage() . "\n";
    exit;
}
Sign up to request clarification or add additional context in comments.

8 Comments

A cant use PDO on Linux only window server
@WebblyBrown: You can use PDO on Linux (at least I'm pretty sure you can, I don't see why not). You just need to make sure the PDO and PDO_MSSQL (may be called PDO_DBLIB) extensions are installed and enabled.
I will take a look into other drivers, this looks promising php.net/manual/en/ref.pdo-odbc.php
You definitely CAN use PDO on Linux. It's all I use and I'm on Linux.
Hmm ive installed the pdo odbc driver above and I still get Failed to get DB handle: could not find driver
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.