<?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)); }
为啥连接只需要提供服务器名字就可以,连接本机的和内网或者外网的服务器都是这样吗?
给个名字就能找到要连的原理是啥?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
通过
serverName
可以找到对应的IP,如果是本机可以不用服务器名,直接用.
。通过sqlexpress
可以知道SQL Server实例名称。本机使用Windows集成验证(Integrated Security=true
)可以不用用户名/密码,如果连接远程的服务器就需要用户名与密码。域名 和 ip是一个意思,