PHP连接msSQL数据库办法
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1.什么是msSQL呢?</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">msSQL<span style="color: black;">指的是</span>微软的SQLServer数据库服务器,它是一个数据库平台,<span style="color: black;">供给</span>数据库的从服务器到终端的完整的<span style="color: black;">处理</span><span style="color: black;">方法</span>,其中数据库服务器部分,是一个数据库管理系统,用于<span style="color: black;">创立</span>、<span style="color: black;">运用</span>和<span style="color: black;">守护</span>数据库。SQL Server一<span style="color: black;">起始</span>并不是微软自己<span style="color: black;">开发</span>的<span style="color: black;">制品</span>,而是当时为了要和IBM竞争时,与Sybase合作所产生的,其最早的发展者是Sybase,<span style="color: black;">同期</span>微软<span style="color: black;">亦</span>和Sybase合作过 SQL Server 4.2版本的<span style="color: black;">开发</span>,微软<span style="color: black;">也</span>将SQL Server 4.2移植到Windows NT(当时为3.1版),在与Sybase终止合作关系后,自力<span style="color: black;">研发</span>出SQL Server 6.0版,往后的SQL Server即均由微软<span style="color: black;">自动</span><span style="color: black;">开发</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">认识</span>完mssql数据库之后,<span style="color: black;">咱们</span>经<span style="color: black;">平常</span>到的是PHP+mysql数据库的组合,这个黄金搭档是公认的最佳组合,<span style="color: black;">咱们</span>今天不说它了,今天<span style="color: black;">来讲</span>说PHP+mssql吧,<span style="color: black;">做为</span>程序猿来讲,经常被<span style="color: black;">各样</span>需求轰炸,什么需求都有,今天正好在做小型项目时<span style="color: black;">发掘</span>PHP<span style="color: black;">必须</span>与mssql数据库连接,<span style="color: black;">第1</span>感觉<span style="color: black;">便是</span>与mysql连接差不多,<span style="color: black;">而后</span>就下手<span style="color: black;">起始</span>了,但在<span style="color: black;">咱们</span>的运行环境里面,很少有人去安装<span style="color: black;">有些</span>模块来支撑这个连接。下面<span style="color: black;">咱们</span><span style="color: black;">一块</span>来<span style="color: black;">瞧瞧</span>怎么连接的吧。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">第1</span>步:下载SQL Server驱动</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">首要</span>来<span style="color: black;">瞧瞧</span><span style="color: black;">咱们</span>的sqlderver扩展是32位还是64位的,不是<span style="color: black;">按照</span>电脑的系统的位数判断的,而是<span style="color: black;">按照</span>php的位数判断的。如下图的红框所示查看,<span style="color: black;">咱们</span>是64位的。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">上面这图怎么查看,可<span style="color: black;">经过</span>下面代码</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo phpinfo();</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">我<span style="color: black;">这儿</span>用的php是PHP Version 7.3.4,要下载对应的扩展版本。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">官方下载地下:<a style="color: black;">Download the Microsoft Drivers for PHP for SQL Ser</a>ver - SQL Server</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1.下载完毕解压出来把php_pdo_sqlsrv_73_nts_x64.dll和</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">php_sqlsrv_73_nts_x64.dll</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">放到D:\phpstudy_pro\Extensions\php\php7.3.4nts\ext(放在你安装PHP的ext目录下面)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2.设置php.ini,把这二个dll模块加进来。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">extension=php_sqlsrv_7_nts_x86.dll</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">extension=php_pdo_sqlsrv_7_nts_x86.dll</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">如下图:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">重视</span>:PHP Version 7.3.4对应的版本是php_sqlsrv_7_nts_x86.dll和php_pdo_sqlsrv_7_nts_x86.dll</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">第二步:安装ODBC驱动11</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">驱动11支持所有版本,<span style="color: black;">因此</span>果断下载11版本:官方下载地下:<a style="color: black;"><span style="color: black;">https://www.</span><span style="color: black;">microsoft.com/en-us/dow</span><span style="color: black;">nload/details.aspx?id=36434</span></a></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下载成功直接安装就<span style="color: black;">能够</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">重视</span>:此时要重新<span style="color: black;">起步</span>apache.</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">第三步:写代码测试<span style="color: black;">是不是</span>能成功</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php $server = "localhost"; //服务器名<span style="color: black;">叫作</span> $uid = "xxx"; //数据库用户名 $pwd = "123456"; //数据库<span style="color: black;">暗码</span> $db = "test"; // 数据库名 $connectionInfo=array("UID"=>$uid,"PWD"=>$pwd,"Database"=>$db); $conn =sqlsrv_connect($server,$connectionInfo); if( $conn == false) { echo "连接失败!"; die( var_dump( sqlsrv_errors(), true)); }else{ echo "成功连接"; }</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span><span style="color: black;">表示</span>“成功连接”,说明<span style="color: black;">已然</span>连接成功了,快去庆祝一下吧</p>
楼主果然英明!不得不赞美你一下! 你字句如珍珠,我珍藏这份情。
页:
[1]