sql >> Database teknologi >  >> RDS >> Sqlserver

Linux - PHP 7.0 og MSSQL (Microsoft SQL)

Microsoft har PHP Linux-drivere til SQL Server til PHP 7 og nyere på PECL. Disse er produktionsklare. Følg disse trin for at downloade dem:

Ubuntu 16.04:

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools unixodbc-dev
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
echo "extension=sqlsrv" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
echo "extension=pdo_sqlsrv" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

CentOS 7:

sudo su
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
exit
sudo yum update
sudo ACCEPT_EULA=Y yum install -y msodbcsql mssql-tools unixODBC-devel 
sudo yum groupinstall "Development Tools"
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
echo "extension=sqlsrv" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
echo "extension=pdo_sqlsrv" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

Dette vil installere PHP SQL Server-driverne og registrere dem i mappen php.ini.

Bekræft, at det virker ved at bruge følgende eksempel

<?php
$serverName = "localhost";
$connectionOptions = array(
    "Database" => "SampleDB",
    "Uid" => "sa",
    "PWD" => "your_password"
);
//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn)
    echo "Connected!"
?>

Links til reference:

  • https://pecl.php.net/package/sqlsrv

  • https://pecl.php.net/package/pdo_sqlsrv

  • https://github.com/Microsoft/msphpsql



  1. pyodbc.connect() virker, men ikke sqlalchemy.create_engine().connect()

  2. Sådan opretter du database i SQL Server ved at bruge TSQL eller GUI - SQL Server / TSQL Tutorial Del 24

  3. hvordan man bruger tns-indgange med macromedia-drivere til Oracle

  4. Ansible elsker PostgreSQL