<?php $serverName = "serverName\sqlexpress"; //serverName\instanceName // Since UID and PWD are not specified in the $connectionInfo array, // The connection will be attempted using Windows Authentication. $connectionInfo = array( "Database"=>"dbName"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); }
为啥连接只需要提供服务器名字就可以,连接本机的和内网或者外网的服务器都是这样吗?
给个名字就能找到要连的原理是啥?
通过serverName
可以找到对应的IP,如果是本机可以不用服务器名,直接用.
。通过sqlexpress
可以知道SQL Server实例名称。本机使用Windows集成验证(Integrated Security=true
)可以不用用户名/密码,如果连接远程的服务器就需要用户名与密码。
想问下如果连接外网的服务器(比如其他省的什么服务器)也是写个名字用户名密码就可以吗?
无法理解如果内网的ip和外网的某个ip是一样的,它咋知道我想连哪个?
@糯米团子滚呀滚: 内网与外网所使用的IP有明确划分,不会是一样的
域名 和 ip是一个意思,
万一重名了嘞