docker 安装sqlserver数据库
sudo docker pull mcr.microsoft.com/mssql/server:2017-latest
sudo docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>" -p 1433:1433 --name sqlserver --hostname sqlserver -d mcr.microsoft.com/mssql/server:2017-latest
SA 帐户是安装过程中在 SQL Server 实例上创建的系统管理员。
php环境配置
增加php扩展
docker中安装 版本不一致问题可以修改 ./extensions/install-php-extensions文件
修改完配置down掉,重新进行运行
install-php-extensions pdo_sqlsrv sqlsrv
ubuntu18.4中安装odbc,执行下脚本
if ! [[ "16.04 18.04 20.04 22.04" == *"$(lsb_release -rs)"* ]];
then
echo "Ubuntu $(lsb_release -rs) is not currently supported.";
exit;
fi
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install -y unixodbc-dev
sqlserver简单查询
$res = $this->sqlServerDb->fetchAll("SELECT * FROM a");
$res = $this->sqlServerDb->fetchAll("SELECT TOP 1 * FROM a");
$res = $this->sqlServerDb->fetchAll("SELECT * FROM a WHERE JobType_CD = '003' AND Status_TX = '在职' AND SyncStatus_CDForITC = '0'");
$res = $this->sqlServerDb->fetchAll("SELECT count(*) as allNum FROM a WHERE JobType_CD = '001' AND Status_TX = '在' AND SyncStatus_CDForITC = '0'");
$conn = sqlsrv_connect( self::IP,['Database'=>self::DATABASE,'UID'=>self::USERNAME,'PWD'=>self::PASSWORD]);
$sql = "SELECT * FROM MS_EMP";
$result = @sqlsrv_query($conn, $sql);
while ( $re = @sqlsrv_fetch_array($result)) {
var_dump($re);
}