{"id":1938,"date":"2018-05-14T17:32:12","date_gmt":"2018-05-14T09:32:12","guid":{"rendered":"https:\/\/blog.nuface.tw\/?p=1938"},"modified":"2018-05-14T17:32:42","modified_gmt":"2018-05-14T09:32:42","slug":"php-%e9%80%a3%e6%8e%a5-mssql-%e5%ae%89%e8%a3%9d%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/blog.nuface.tw\/?p=1938","title":{"rendered":"PHP \u9023\u63a5 MSSQL \u5b89\u88dd\u65b9\u5f0f"},"content":{"rendered":"<p>\u4e4b\u524d\u5927\u90fd\u4f7f\u7528PHP \u9023\u63a5 mysql \uff0c\u5de5\u4f5c\u9700\u8981\u5fc5\u9808\u9023\u63a5MSSQL \u8cc7\u6599\u5eab\u3002\u4e0d\u96e3\u5b89\u88dd\u8a2d\u5b9a\uff0c\u4f46\u6015\u5fd8\u8a18\uff0c\u5c31\u8a18\u9304\u4e00\u4e0b\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/\/blog.nuface.tw\/wp-content\/uploads\/2018\/05\/forget.jpg\" alt=\"forget\" \/><\/p>\n<p><!--more--><\/p>\n<p>\u74b0\u5883: CentOS 7  \/ Apache 2.4.6  \/ PHP 7.1<\/p>\n<p>\u5b89\u88dd\u4e86 epel-release \/ remi-release-7<\/p>\n<p>\u5982\u679c\u8981\u9023\u63a5MSSQL \u8cc7\u6599\u5eab\uff0c\u5148\u4e0b\u8f09 msodbcsql-13.1.9.2-1.x86_64.rpm<\/p>\n<p>\u9032\u884c\u5b89\u88dd<\/p>\n<blockquote><p>\nwget https:\/\/packages.microsoft.com\/rhel\/7\/prod\/msodbcsql-13.1.9.2-1.x86_64.rpm<br \/>\nrpm -ivh msodbcsql-13.1.9.2-1.x86_64.rpm\n<\/p><\/blockquote>\n<p>\u63a5\u8457\u5b89\u88dd<\/p>\n<blockquote><p>\nyum install php71-php-sqlsrv\n<\/p><\/blockquote>\n<p>\u9019\u6a23\u5b50\u6a5f\u5668\u5c31\u6709\u9023\u7dda\u5230 MSSQL \u7684\u80fd\u529b\u4e86\u3002<\/p>\n<p>\u53ef\u4ee5\u7528\u9019\u8173\u672c\u6e2c\u8a66:<\/p>\n<blockquote><p>\n$dsn = &#8216;dblib:dbname=testdb;host=mssql.abc.com&#8217;;<br \/>\n$user = &#8216;testuser&#8217;;<br \/>\n$password = &#8216;test123&#8217;;<br \/>\n$connection = new PDO($dsn, $user, $password);<\/p>\n<p>$sql  =  &#8216;select top 2 * from dbo.testtable &#8216;;<\/p>\n<p>foreach ($connection->query($sql) as $row) {<br \/>\n    var_dump($row);<br \/>\n}<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u5927\u90fd\u4f7f\u7528PHP \u9023\u63a5 mysql \uff0c\u5de5\u4f5c\u9700\u8981\u5fc5\u9808\u9023\u63a5MSSQL \u8cc7\u6599\u5eab\u3002\u4e0d\u96e3\u5b89\u88dd\u8a2d\u5b9a\uff0c\u4f46\u6015\u5fd8\u8a18\uff0c\u5c31\u8a18\u9304\u4e00\u4e0b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[313],"tags":[315,314],"class_list":["post-1938","post","type-post","status-publish","format-standard","hentry","category-php","tag-mssql","tag-php"],"_links":{"self":[{"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/posts\/1938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1938"}],"version-history":[{"count":3,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/posts\/1938\/revisions"}],"predecessor-version":[{"id":1942,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=\/wp\/v2\/posts\/1938\/revisions\/1942"}],"wp:attachment":[{"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nuface.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}