ubuntu php sqlserver,TinkPHP5 使用sqlserver

  • Post author:
  • Post category:php


在 Ubuntu 16.04 和 17.10 上安装驱动程序

步骤 1. 安装必备组件步骤 1. 安装必备组件

Ubuntu 14.04,16.04 和 17.10

sudo su

curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add –

#Download appropriate package for the OS version

#Choose only ONE of the following, corresponding to your OS version

#Ubuntu 14.04

curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Ubuntu 16.04

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Ubuntu 17.10

curl https://packages.microsoft.com/config/ubuntu/17.10/prod.list > /etc/apt/sources.list.d/mssql-release.list

exit

sudo apt-get update

sudo ACCEPT_EULA=Y apt-get install msodbcsql17

# optional: for bcp and sqlcmd

sudo ACCEPT_EULA=Y apt-get install mssql-tools

echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bash_profile

echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bashrc

source ~/.bashrc

# optional: for unixODBC development headers

sudo apt-get install unixodbc-dev

步骤 2. 安装 Microsoft SQL Server PHP 驱动程序步骤

sudo pecl install sqlsrv

sudo pecl install pdo_sqlsrv

sudo su

echo extension=pdo_sqlsrv.so >> `php –ini | grep “Scan for additional .ini files” | sed -e “s|.*:\s*||”`/30-pdo_sqlsrv.ini

echo extension=sqlsrv.so >> `php –ini | grep “Scan for additional .ini files” | sed -e “s|.*:\s*||”`/20-sqlsrv.ini

exit

步骤3 . 配置驱动程序加载步骤3 . 配置驱动程序加载

直接在php.ini 中加入

extension=pdo_sqlsrv.so

extension=sqlsrv.so

重启服务

在 CentOs7上安装驱动程序在 CentOs7上安装驱动程序

步骤 1. 安装必备组件步骤 1. 安装必备组件

CentOs Server 6 和 7

查看系统版本 :cat /etc/redhat-release

sudo su

Download appropriate package for the OS version

#Choose only ONE of the following, corresponding to your OS version

#CentOs Enterprise Server 6

curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo

#CentOs Enterprise Server 7

curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo

exit

sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts

sudo ACCEPT_EULA=Y yum install msodbcsql17

# optional: for bcp and sqlcmd

sudo ACCEPT_EULA=Y yum install mssql-tools

echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bash_profile

echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bashrc

source ~/.bashrc

# optional: for unixODBC development headers

sudo yum install unixODBC-devel

步骤 2. 安装 Microsoft SQL Server PHP 驱动程序

sudo pecl install sqlsrv

sudo pecl install pdo_sqlsrv

sudo su

echo extension=pdo_sqlsrv.so >> `php –ini | grep “Scan for additional .ini files” | sed -e “s|.*:\s*||”`/30-pdo_sqlsrv.ini

echo extension=sqlsrv.so >> `php –ini | grep “Scan for additional .ini files” | sed -e “s|.*:\s*||”`/20-sqlsrv.ini

exit

即使你已升级 GCC PECL 中的问题可能会阻止驱动程序的最新版本的正确安装。 若要安装,请下载包并手动编译:

pecl download sqlsrv

tar xvzf sqlsrv-5.2.0.tgz

cd sqlsrv-5.2.0/

phpize

./configure –with-php-config=/usr/bin/php-config

make

sudo make install

或者,你可以下载的预构建的二进制文件从Github 项目页,或从 Remi 存储库安装:

sudo yum install php-sqlsrv php-pdo_sqlsrv

步骤 3. 配置驱动程序加载步骤

直接在php.ini 中加入

extension=pdo_sqlsrv.so

extension=sqlsrv.so

重启服务

附上database.php附上database.php

// +———————————————————————-

// | ThinkPHP [ WE CAN DO IT JUST THINK ]

// +———————————————————————-

// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.

// +———————————————————————-

// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )

// +———————————————————————-

// | Author: liu21st

// +———————————————————————-

use think\Env;

return [

// 数据库类型

‘type’ => Env::get(‘database.type’, ‘sqlsrv’),

// 服务器地址

‘hostname’ => Env::get(‘database.hostname’, ‘192.168.1.188’),

// 数据库名

‘database’ => Env::get(‘database.database’, ‘QPTreasureDB’),

// 用户名

‘username’ => Env::get(‘database.username’, ‘admin’),

// 密码

‘password’ => Env::get(‘database.password’, ‘123456’),

// 端口

‘hostport’ => Env::get(‘database.hostport’, ”),

// 连接dsn

‘dsn’ => ”,

// 数据库连接参数

‘params’ => [],

// 数据库编码默认采用utf8

‘charset’ => Env::get(‘database.charset’, ‘Gbx’),

// 数据库表前缀

//’prefix’ => Env::get(‘database.prefix’, ‘fa_’),

// 数据库调试模式

‘debug’ => Env::get(‘database.debug’, true),

// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)

‘deploy’ => 0,

// 数据库读写是否分离 主从式有效

‘rw_separate’ => false,

// 读写分离后 主服务器数量

‘master_num’ => 1,

// 指定从服务器序号

‘slave_no’ => ”,

// 是否严格检查字段是否存在

‘fields_strict’ => true,

// 数据集返回类型

‘resultset_type’ => ‘array’,

// 自动写入时间戳字段

‘auto_timestamp’ => false,

// 时间字段取出后的默认时间格式,默认为Y-m-d H:i:s

‘datetime_format’ => false,

// 是否需要进行SQL性能分析

‘sql_explain’ => false,

];