1.安装php运行环境phpstudy
2.把文件复制到www目录
3. 下载微软的php连接驱动:SQLSRV30.EXE(5.4对应,后面的native client要用2008)
4. 然后打开php.ini文件,在extension 后面添加一下配置
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_sqlsrv_54_nts.dll
重启apache,查看phpinfo(),确保apache已经支持sqlsrv
2.把文件复制到www目录
3. 下载微软的php连接驱动:SQLSRV30.EXE(5.4对应,后面的native client要用2008)
4. 然后打开php.ini文件,在extension 后面添加一下配置
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_sqlsrv_54_nts.dll
重启apache,查看phpinfo(),确保apache已经支持sqlsrv
PDO
PDO support |
enabled |
PDO drivers |
Mysal,odbc,sqlite,sqlite2,sqlsrv |
Dpo_sqlsrv support |
enabled |
https://www.microsoft.com/en-us/download/details.aspx?id=36434
6.输入账号密码
public function index(){
$serverName = \"\"; //数据库服务器地址
$uid = \"\"; //数据库用户名
$pwd = \"\"; //数据库密码
$connectionInfo = array(\"UID\"=>$uid, \"PWD\"=>$pwd, \"Database\"=>\"ekp\");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn == false)
{
echo \"连接失败!\";
die( print_r( sqlsrv_errors(), true));
}else{
echo \"连接成功!\"; }}
7.打开网站的IndexController显示链接成功代表连上sqlseaver数据库