I'm try to connect from php using laravel framewrok to SQL Server, My php version is 5.5.30, PDO drivers installed are: mysql, sqlite, pgsql, odbc. using webServer (MAMP) in OS X El Capitan.
To connect i'm using FreeTDS and unixODBC, both libraries was installed using this articule. https://gist.github.com/Bouke/10454272 and work perfect from terminal.
I'm using the follow code in php file.
$db = new PDO('odbc:Driver=FreeTDS; Server=192.168.1.1; Port=4433; Database=focalyx; UID=myUser; PWD=myPassword;');
}
catch(PDOException $exception)
{
die("Unable to open database.<br />Error message:<br /><br />$exception.");
}
echo '<h1>Successfully connected!</h1>';
$query = 'SELECT * FROM Users';
try{
$statement = $db->prepare($query);
$statement->execute();
}catch(PDOException $exception){
die("Unable to open database.<br />Error message:<br /><br />$exception.");
}
$result = $statement->fetchAll(PDO::FETCH_NUM);
print_r($result);
however when try to run from localhost, show the this error.
exception 'PDOException' with message 'SQLSTATE[01000] SQLDriverConnect: 0 [unixODBC][Driver Manager]Can't open lib 'FreeTDS' : file not found' in /Applications/MAMP/htdocs/myProject/test.php:5 Stack trace: #0 /Applications/MAMP/htdocs/myProject/test.php(5): PDO->__construct('odbc:Driver=Fre...') #1 {main}.
php is installed in
/Applications/MAMP/bin/php/php5.6.10/conf/php.ini
I don't know if is possible install FreeTDS into MAMP dir or create a kind of symbolic link.