{"id":1862,"date":"2021-11-29T21:13:52","date_gmt":"2021-11-29T18:13:52","guid":{"rendered":"https:\/\/burakcaliskan.org\/blog\/?p=1862"},"modified":"2021-11-29T21:15:53","modified_gmt":"2021-11-29T18:15:53","slug":"php-unixodbc","status":"publish","type":"post","link":"https:\/\/burakcaliskan.org\/blog\/php-unixodbc\/","title":{"rendered":"PHP Centos unixODBC"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">yum remove unixODBC*\n\n# CentOS 6\ncurl https:\/\/packages.microsoft.com\/config\/rhel\/6\/prod.repo &gt; \/etc\/yum.repos.d\/mssql-release.repo\n\n\n# CentOS 7\ncurl https:\/\/packages.microsoft.com\/config\/rhel\/7\/prod.repo &gt; \/etc\/yum.repos.d\/mssql-release.repo\n\n\nACCEPT_EULA=Y yum install msodbcsql17 unixODBC unixODBC-devel\n\n\n\n<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$serverName = \"your server hostname\/IP, port\";\n$connectionOptions = array(\n    \"database\" =&gt; \"yourDatabase\",\n    \"uid\" =&gt; \"yourUsername\",\n    \"pwd\" =&gt; \"yourPassword\"\n);\n\n\/\/ Establishes the connection\n$conn = sqlsrv_connect($serverName, $connectionOptions);\nif ($conn === false) {\n    die(formatErrors(sqlsrv_errors()));\n}\n\n\/\/ Select Query\n$tsql = \"SELECT @@Version AS SQL_VERSION\";\n\n\/\/ Executes the query\n$stmt = sqlsrv_query($conn, $tsql);\n\n\/\/ Error handling\nif ($stmt === false) {\n    die(formatErrors(sqlsrv_errors()));\n}\n?&gt;\n\n&lt;h1&gt; Results : &lt;\/h1&gt;\n\n&lt;?php\nwhile ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {\n    echo $row&#91;'SQL_VERSION'] . PHP_EOL;\n}\n\nsqlsrv_free_stmt($stmt);\nsqlsrv_close($conn);\n\nfunction formatErrors($errors)\n{\n    \/\/ Display errors\n    echo \"Error information: &lt;br\/&gt;\";\n    foreach ($errors as $error) {\n        echo \"SQLSTATE: \". $error&#91;'SQLSTATE'] . \"&lt;br\/&gt;\";\n        echo \"Code: \". $error&#91;'code'] . \"&lt;br\/&gt;\";\n        echo \"Message: \". $error&#91;'message'] . \"&lt;br\/&gt;\";\n    }\n}\n?&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>yum remove unixODBC* # CentOS 6 curl https:\/\/packages.microsoft.com\/config\/rhel\/6\/prod.repo &gt; \/etc\/yum.repos.d\/mssql-release.repo # CentOS 7 curl https:\/\/packages.microsoft.com\/config\/rhel\/7\/prod.repo &gt; \/etc\/yum.repos.d\/mssql-release.repo ACCEPT_EULA=Y yum install msodbcsql17 unixODBC unixODBC-devel<\/p>\n","protected":false},"author":2,"featured_media":1865,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[253,1096,22],"tags":[67,388,1242,25,187],"_links":{"self":[{"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/posts\/1862"}],"collection":[{"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/comments?post=1862"}],"version-history":[{"count":2,"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/posts\/1862\/revisions"}],"predecessor-version":[{"id":1866,"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/posts\/1862\/revisions\/1866"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/media\/1865"}],"wp:attachment":[{"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/media?parent=1862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/categories?post=1862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/burakcaliskan.org\/blog\/wp-json\/wp\/v2\/tags?post=1862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}