Debian/PHP Connect to MS SQL Server

Se connecter à un serveur MSSQL avec PDO, ODBC et FreeTDS

Sur votre debian installer:

apt-get install freetds-bin freetds-common tdsodbc odbcinst php5-odbc unixodbc

cp /usr/share/doc/freetds-common/examples/odbcinst.ini /etc/odbcinst.ini

Exemple de script PHP:

<?php

try {
    $db = new PDO('odbc:Driver=FreeTDS; Server=192.168.1.2; Port=1433; Database=test; UID=root; PWD=toor;');
}
catch(PDOException $e) {

    die("Unable to open database.<br>Error message:<br><br>$e.");
}

echo '<h1>Successfully connected!</h1>';

$query = 'SELECT * FROM user;';
$statement = $db->prepare($query);
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_NUM);

print_r( $result );

Source: secure.kitserve.org.uk