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:


try {
    $db = new PDO('odbc:Driver=FreeTDS; Server=; 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);
$result = $statement->fetchAll(PDO::FETCH_NUM);

print_r( $result );