解决方法
PHP 5.6
Ubuntu的
sudo apt-get install PHP5.6-sybase freetds-common libsybdb5
AWS / Centos / Redhat
sudo yum install PHP56-mssql
<?PHP $server = 'localhost'; $user = 'someUser'; $pass = 'somePassword'; $database = 'theDatabaseName'; try { $pdo = new \PDO( sprintf( "dblib:host=%s;dbname=%s",$server,$database ),$user,$pass ); $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo "There was a problem connecting. " . $e->getMessage(); } $query = "SELECT * FROM TestSchema.Employees"; $statement = $pdo->prepare($query); $statement->execute(); $results = $statement->fetchAll(PDO::FETCH_ASSOC); var_dump($results);
tsql -H your.server.name -p 1433 -U yourusername -P yourpassword -D yourdatabasename
PHP 7
Microsoft有我们可以使用的本机驱动程序.完整说明是here (Redhat / Ubuntu / Others).
该链接还包含在您的开发机器上安装Ms sql服务器所需的步骤(在Ubuntu上工作,在AWS上不起作用,但您可以在那里启动RDS实例).它还包含有关如何在数据库中创建测试表和数据的基本指令,以及PHP连接代码.