{"id":114,"date":"2017-03-07T12:14:26","date_gmt":"2017-03-07T09:14:26","guid":{"rendered":"http:\/\/antyat.ru\/?p=114"},"modified":"2017-03-07T12:14:26","modified_gmt":"2017-03-07T09:14:26","slug":"how-to-install-microsofts-sql-server-driver-for-php","status":"publish","type":"post","link":"http:\/\/antyat.ru\/?p=114","title":{"rendered":"How to install Microsoft&#8217;s SQL Server Driver for PHP"},"content":{"rendered":"<p>There are questions on <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/sqldriverforphp\/\" target=\"_blank\">Microsoft&#8217;s SQL Server driver for PHP forum<\/a> from people that cannot work out how to install the PHP driver.<\/p>\n<p>PHP offers some help on choosing extensions here:\u00a0<a href=\"http:\/\/php.net\/manual\/en\/install.pecl.windows.php\" target=\"_blank\">http:\/\/php.net\/manual\/en\/install.pecl.windows.php<\/a>, and here: <a href=\"http:\/\/php.net\/manual\/en\/install.windows.extensions.php\" target=\"_blank\">http:\/\/php.net\/manual\/en\/install.windows.extensions.php<\/a>.<\/p>\n<p>It&#8217;s still a bit complicated, so here are some explicit instructions which I hope can help new users of PHP.\u00a0 After a while all of this will become common sense.<\/p>\n<p><a name=\"more\"><\/a><\/p>\n<p>Instruction notes:<\/p>\n<ol>\n<li>Microsoft&#8217;s PHP driver for SQL Server only runs with PHP 32-bit builds (as standard from <a href=\"http:\/\/windows.php.net\/download\" target=\"_blank\">http:\/\/windows.php.net\/download<\/a>).<\/li>\n<li>These instructions are only for PHP 5.2, 5.3 or 5.4. (5.5 and 5.6 supported with custom build.)<\/li>\n<li>I am pretending that PHP is installed into folder C:\\PHP.\u00a0 Replace the term C:\\PHP in the instructions with whatever folder your PHP is installed into.<\/li>\n<li>See orange text for PHP 5.5 and 5.6\u00a0support in 32 and 64 bits. \u00a0If you do not know whether you have 64-bit PHP 5.5\/5.6, start the instructions at step 5, note the orange comment in 5.3, then return to step 1 of the instructions below.<\/li>\n<\/ol>\n<p>Instructions:<\/p>\n<ol>\n<li>Download Microsoft&#8217;s PHP drivers.\u00a0 Open page: <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=20098\" target=\"_blank\">http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=20098<\/a>\n<ol>\n<li>If you have Windows Vista, Server 2008 or above, download SQLSRV30.EXE.<\/li>\n<li>If you have Server 2003\/Windows XP or below, download SQLSRV20.EXE<\/li>\n<li><i>If you have PHP 5.5\/5.6, or you have Windows XP\/2003 and you want to install driver 3.0&#8230;<\/i>\n<ol>\n<li><i>See this post: <a href=\"http:\/\/robsphp.blogspot.com\/2012\/06\/unofficial-microsoft-sql-server-driver.html\" target=\"_blank\">Unofficial php_sqlsrv 3.0<\/a> and download the archive<\/i><\/li>\n<li><i>Note the text in orange in step (2.) below &#8212; you don&#8217;t need to extract the &#8216;source code&#8217; folder. \u00a0Also&#8230;<\/i>\n<ol>\n<li><i>If you have 64-bit PHP, you need to extract <u>only<\/u> the files in sub-folder <b>x64<\/b>\u00a0of the zip file, and can ignore everything else.<\/i><\/li>\n<li><i>If you have 32-bit PHP, you should ignore the folder <b>x64<\/b>\u00a0in the zip file.<\/i><\/li>\n<\/ol>\n<\/li>\n<li><i>Assume for step (6.) below that you downloaded\u00a0<b>SQLSRV30.EXE<\/b><\/i><\/li>\n<li><i>Remember that PHP 5.5+ does not work on Windows XP\/2003 &#8212; for this OS you can only go up to PHP 5.4.<br \/>\n<\/i><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>Extract the entire contents of the file downloaded in (1.) to your PHP extensions folder.\u00a0 This is usually a sub-folder of the location where php is installed, named &#8216;ext&#8217;, e.g. C:\\PHP\\ext.<br \/>\n<i>Note that you can use <a href=\"http:\/\/www.rarlab.com\/download.htm\" target=\"_blank\">WinRAR<\/a> to open the .exe file and extract the files, if you want.<\/p>\n<p>For users of the\u00a0<a href=\"http:\/\/robsphp.blogspot.com\/2012\/06\/unofficial-microsoft-sql-server-driver.html\" target=\"_blank\">Unofficial php_sqlsrv 3.0<\/a>\u00a0zip file:<\/i><\/p>\n<ol>\n<li><i>If you have 64-bit PHP, please extract only the contents of folder <b>x64 <\/b>of the zip file.<\/i><\/li>\n<li><i>If you have 32-bit PHP, extract the files in the root of the zip and ignore any folders.<br \/>\n<\/i><\/li>\n<\/ol>\n<\/li>\n<li>Download the SQL Server Native Client (SNAC), the PHP driver depends on it:\n<ol>\n<li>For SQLSRV30.EXE (Windows Vista and above), go here: <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=29065#SNAC\" target=\"_blank\">http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=29065#SNAC<\/a>. \u00a0These are <b>direct links<\/b>:\n<ol>\n<li><a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=239648&amp;clcid=0x409\" target=\"_blank\">SQL Server 2012 Native Client for 64 Bit Windows<\/a>\u00a0(x64)<\/li>\n<li><a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=239647&amp;clcid=0x409\" target=\"_blank\">SQL Server 2012 Native Client for 32 Bit Windows<\/a>\u00a0(x86)<\/li>\n<\/ol>\n<\/li>\n<li>For SQLSRV20.EXE (Windows XP\/2003), go here: <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=16978#SNAC\" target=\"_blank\">http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=16978#SNAC<\/a>. \u00a0Here are the <b>direct links<\/b>:\n<ol>\n<li><a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=188401&amp;clcid=0x409\" target=\"_blank\">SQL Server 2008r2 Native Client for 64 Bit Windows<\/a> (x64)<\/li>\n<li><a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=188400&amp;clcid=0x409\" target=\"_blank\">SQL Server 2008r2 Native Client for 32 Bit Windows<\/a> (x86)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>Install the SQL Server Native Client downloaded from the previous step (3.) on the same computer that runs PHP.<\/li>\n<li>Find out which version of PHP you have (if you already know it, go to step 6):\n<ol>\n<li>Open a command window (run cmd.exe)<\/li>\n<li>Using your PHP folder, run command: &#171;C:\\PHP\\php.exe&#187; -i | more<br \/>\n<i>&#8216;more&#8217; loads the information page by page.<\/i><\/li>\n<li>The top line will show <i>PHP Version =&gt; 5.x.x&#8230;<\/i>\u00a0 Make a note of the version.\u00a0 It will start with 5.6, 5.5, 5.4, 5.3 or 5.2.\u00a0 The final (3rd) number is not important.PHP 5.5+ users can also tell if they have a 64-bit or 32-bit version of PHP by looking at the reported <i><b>Architecture<\/b><\/i>:\u00a0<b>x86<\/b> = <b>32-bit<\/b> and <b>x64<\/b> = <b>64-bit<\/b>.<i>For the next steps you may need to scroll to the 2nd information page in the console window, by pressing the space bar&#8230;<\/i><\/li>\n<li><b><i>For version 5.6, 5.5, 5.4 and 5.3<\/i><\/b>, a little further down is setting <i>PHP Extension Build =&gt; API&#8230;<\/i> It will end with either &#8230;TS,VCn or &#8230;NTS,VCn.\u00a0 Make a note of whether it says TS or NTS.\u00a0 Also make a note of whether the final part is VC11, VC9 or VC6 (VC6 is still possible with PHP 5.3 and SQLSRV20.EXE).<\/li>\n<li><b><i>For PHP version 5.2 only<\/i><\/b>: note the setting that says &#171;Thread Safety enabled&#187; or &#171;Thread Safety disabled&#187;.<br \/>\n&#171;Thread Safety enabled&#187; means TS,VC6<br \/>\n&#171;Thread Safety disabled&#187; means NTS,VC6.<\/li>\n<\/ol>\n<\/li>\n<li>Edit your php configuration file, php.ini.\u00a0 Go to the end of the file and add these lines, depending on your earlier choices.\u00a0 You need to know your PHP version number (5.2, 5.3, 5.4, 5.5\u00a0or 5.6), and your TS\/NTS setting, and whether you have a VC11, VC9 or VC6 build, all noted from step 5. above.\n<p>You can calculate the files you need by looking at the file name and comparing to your PHP version, and remembering whether you downloaded SQLSRV20.exe or SQLSRV30.exe.\u00a0 Here are all of the combinations that are possible:<\/p>\n<ul>\n<li>For the custom drivers, PHP 5.6, NTS, VC11 add lines:\n<div>extension=php_sqlsrv_56_nts.dll<br \/>\nextension=php_pdo_sqlsrv_56_nts.dll<\/div>\n<\/li>\n<li>For the custom drivers, PHP 5.6, TS, VC11 add lines:\n<div>extension=php_sqlsrv_56_ts.dll<br \/>\nextension=php_pdo_sqlsrv_56_ts.dll<\/div>\n<\/li>\n<li>For the custom drivers, PHP 5.5, NTS, VC11 add lines:\n<div>extension=php_sqlsrv_55_nts.dll<br \/>\nextension=php_pdo_sqlsrv_55_nts.dll<\/div>\n<\/li>\n<li>For the custom drivers, PHP 5.5, TS, VC11 add lines:\n<div>extension=php_sqlsrv_55_ts.dll<br \/>\nextension=php_pdo_sqlsrv_55_ts.dll<\/div>\n<\/li>\n<li>For SQLSRV30.EXE (or the custom drivers), PHP 5.4, NTS, VC9 add lines:\n<div>extension=php_sqlsrv_54_nts.dll<br \/>\nextension=php_pdo_sqlsrv_54_nts.dll<\/div>\n<\/li>\n<li>For SQLSRV30.EXE (or the custom drivers), PHP 5.4, TS, VC9 add lines:\n<div>extension=php_sqlsrv_54_ts.dll<br \/>\nextension=php_pdo_sqlsrv_54_ts.dll<\/div>\n<\/li>\n<li>For SQLSRV30.EXE (or the custom drivers), PHP 5.3, NTS, VC9 add lines:\n<div>extension=php_sqlsrv_53_nts.dll<br \/>\nextension=php_pdo_sqlsrv_53_nts.dll<\/div>\n<\/li>\n<li>For SQLSRV30.EXE (or the custom drivers), PHP 5.3, TS, VC9 add lines:\n<div>extension=php_sqlsrv_53_ts.dll<br \/>\nextension=php_pdo_sqlsrv_53_ts.dll<\/div>\n<\/li>\n<li>For SQLSRV20.EXE, PHP 5.3, NTS, VC9 add lines:\n<div>extension=php_sqlsrv_53_nts_vc9.dll<br \/>\nextension=php_pdo_sqlsrv_53_nts_vc9.dll<\/div>\n<\/li>\n<li>For SQLSRV20.EXE, PHP 5.3, NTS, VC6 add lines:\n<div>extension=php_sqlsrv_53_nts_vc6.dll<br \/>\nextension=php_pdo_sqlsrv_53_nts_vc6.dll<\/div>\n<\/li>\n<li>For SQLSRV20.EXE, PHP 5.3, TS, VC9 add lines:\n<div>extension=php_sqlsrv_53_ts_vc9.dll<br \/>\nextension=php_pdo_sqlsrv_53_ts_vc9.dll<\/div>\n<\/li>\n<li>For SQLSRV20.EXE, PHP 5.3, TS, VC6 add lines:\n<div>extension=php_sqlsrv_53_ts_vc6.dll<br \/>\nextension=php_pdo_sqlsrv_53_ts_vc6.dll<\/div>\n<\/li>\n<li>For SQLSRV20.EXE, PHP 5.2, NTS, VC6 add lines:\n<div>extension=php_sqlsrv_52_nts_vc6.dll<br \/>\nextension=php_pdo_sqlsrv_52_nts_vc6.dll<\/div>\n<\/li>\n<li>For SQLSRV20.EXE, PHP 5.2, TS, VC6 add lines:\n<div>extension=php_sqlsrv_52_ts_vc6.dll<br \/>\nextension=php_pdo_sqlsrv_52_ts_vc6.dll<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<li>Restart your web server for the change to take effect. \u00a0That means stop and start IIS, Apache, or whatever you use, not the whole computer.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>There are questions on Microsoft&#8217;s SQL Server driver for PHP forum from people that cannot work out how to install the PHP driver. PHP offers some help on choosing extensions here:\u00a0http:\/\/php.net\/manual\/en\/install.pecl.windows.php, and here: http:\/\/php.net\/manual\/en\/install.windows.extensions.php. It&#8217;s still a bit complicated, so here are some explicit instructions which I hope can help new users of PHP.\u00a0 After [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-114","post","type-post","status-publish","format-standard","hentry","category-1"],"_links":{"self":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts\/114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=114"}],"version-history":[{"count":1,"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":115,"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions\/115"}],"wp:attachment":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}