{"id":3356,"date":"2016-11-14T14:08:05","date_gmt":"2016-11-14T06:08:05","guid":{"rendered":"http:\/\/blog.hoyo.idv.tw\/?p=3356"},"modified":"2018-04-30T09:34:19","modified_gmt":"2018-04-30T01:34:19","slug":"php-pdo-%e7%9a%84-sql-server-%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=3356","title":{"rendered":"\u5f9e CentOS \u7684 PHP  \u5b58\u53d6 Windows SQL Server \u53ca\u8a9e\u6cd5\u4f7f\u7528\u5099\u8a3b"},"content":{"rendered":"<p><span style=\"color: #ff6600;\">\u4f7f\u7528\u81ea\u8a02 repo \u7684\u65b9\u5f0f\u7121\u6cd5\u9806\u5229\u5b89\u88dd php-gd \u7b49\u5f85\u6e2c\u8a66\u66f4\u65b0<\/span><\/p>\n<p>--<\/p>\n<p>\u53c3\u8003<\/p>\n<ul>\n<li><a href=\"http:\/\/qiita.com\/ozawan\/items\/caf6e7ddec7c6b31f01e\" target=\"_blank\" rel=\"noopener\">CentOS6\uff0fCentOS7\u306bPHP5.6\uff0fPHP7\u3092yum\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/li>\n<\/ul>\n<p>--<\/p>\n<h2>\u5b89\u88dd php-mssql<\/h2>\n<pre class=\"lang:default decode:true\">yum install php-mssql<\/pre>\n<p>--<\/p>\n<h2>PHP \u7bc4\u4f8b\u7a0b\u5f0f<\/h2>\n<pre class=\"lang:php decode:true\">&lt;?php\r\n$link = mssql_connect('Server IP', 'Username', 'Password');\r\nif (!$link)\r\n    die('error');\r\nelse\r\n    echo('ok');\r\n\r\n$sql = \" SELECT * FROM dbo.batch_id \";\r\n$query = mssql_query($sql);\r\n$row = mssql_fetch_array($query);\r\n\r\nprint_r($row);\r\n<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"lang:php decode:true \">&lt;?php\r\n$dsn = 'dblib:host=Server IP;dbname=Database Name;';\r\n$user = 'Username';\r\n$password = 'Password';\r\n\r\n\/\/ \u5efa\u7acb PDO \u7269\u4ef6\r\n$pdo = new PDO($dsn, $user, $password);\r\n\r\n$sql = \" SELECT * FROM database.dbo.table \";\r\n$pre = $pdo-&gt;prepare($sql);\r\n$pre-&gt;execute();\r\n$row = $pre-&gt;fetchAll(2);\r\n\r\nprint_r($row);\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>--<\/p>\n<h2>UTF-8 \u8a2d\u5b9a<\/h2>\n<p>\u53c3\u8003<\/p>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/13377812\/getting-data-with-utf-8-charset-from-mssql-server-using-php-freetds-extension\">Getting data with UTF-8 charset from MSSQL server using PHP FreeTDS extension<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/25314965\/freetds-return-utf-8-character-set-data\">FreeTDS - Return UTF-8 Character Set Data<\/a><\/li>\n<\/ul>\n<p>vi \/etc\/freetds.conf<\/p>\n<pre class=\"lang:default decode:true\">[global]\r\n    # TDS protocol version\r\n    tds version = 7.0\r\n\r\n    client charset = UTF-8<\/pre>\n<p>&nbsp;<\/p>\n<p>--<\/p>\n<ul>\n<li><a href=\"http:\/\/kingfff.blogspot.tw\/2012\/08\/sybase-mssql-query-connection-timeout.html\" target=\"_blank\" rel=\"noopener\">php\u5b58\u53d6mssql\u3001sybase\u6642\uff0c\u5982\u4f55\u8a2d\u5b9aquery timeout<\/a><\/li>\n<li><a href=\"http:\/\/www.freetds.org\/userguide\/confirminstall.htm\" target=\"_blank\" rel=\"noopener\">FreeTDS\u00a0Confirm the installation<\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \">[root@localhost:~] # tsql -C\r\nCompile-time settings (established with the \"configure\" script)\r\n                            Version: freetds v0.91\r\n             freetds.conf directory: \/etc\r\n     MS db-lib source compatibility: yes\r\n        Sybase binary compatibility: yes\r\n                      Thread safety: yes\r\n                      iconv library: yes\r\n                        TDS version: 4.2\r\n                              iODBC: no\r\n                           unixodbc: yes\r\n              SSPI \"trusted\" logins: no\r\n                           Kerberos: yes<\/pre>\n<p>&nbsp;<\/p>\n<p>--<\/p>\n<h2>MS SQL Server \u8a9e\u6cd5<\/h2>\n<pre class=\"lang:default decode:true \">INSERT INTO table ( [column] ) VALUES ( 'column' )<\/pre>\n<p>\u9019\u662f\u4e00\u500b\u5f88\u7c21\u55ae\u7684\u7bc4\u4f8b\uff0cSQL Server \u7684\u6b04\u4f4d\u540d\u7a31\u4ee5 []\u00a0\u65b9\u62ec\u5f27\u5305\u4f4f\uff0c\u503c\u4e5f\u662f\u4f7f\u7528 ' \u55ae\u5f15\u865f<\/p>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"3356\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,582&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u81ea\u8a02 repo \u7684\u65b9\u5f0f\u7121\u6cd5...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"3356\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,582&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[260],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3356"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3356"}],"version-history":[{"count":9,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3356\/revisions"}],"predecessor-version":[{"id":4539,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3356\/revisions\/4539"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}