{"id":714,"date":"2011-04-07T10:41:31","date_gmt":"2011-04-07T15:41:31","guid":{"rendered":"http:\/\/www.shainmiley.com\/wordpress\/?p=714"},"modified":"2011-04-16T18:45:21","modified_gmt":"2011-04-16T23:45:21","slug":"connecting-to-mssql-using-php-on-linux","status":"publish","type":"post","link":"https:\/\/www.shainmiley.com\/wordpress\/2011\/04\/07\/connecting-to-mssql-using-php-on-linux\/","title":{"rendered":"Connecting to Mssql database servers using PHP on Linux"},"content":{"rendered":"<p>I recently had the pleasure(!) of trying to get PHP on Debian working correctly with a Microsoft SQL server so that the data could be migrated from a Mssql instance into a Mysql one.<\/p>\n<p>Previous to this attempt, the developers were using a Windows machine as a &#8216;broker&#8217; between the two database.  This setup was much too slow for importing and exporting large amounts of data, \u00c2\u00a0so we decided to cut out the middle man (the Windows machine) and do all the processing on a single server.<\/p>\n<p>First I needed to install a few prerequisite packages:<\/p>\n<pre id=\"terminal\">apt-get install unixodbc-dev<\/pre>\n<pre id=\"terminal\">apt-get install libmysqlclient15-dev<\/pre>\n<p>Next we need to download and uncompress the FreeTDS source code:<\/p>\n<pre id=\"terminal\">wget ftp:\/\/ftp.linuxforum.hu\/mirrors\/frugalware\/pub\/frugalware\/frugalware-testing\/source\/lib-extra\/freetds\/freetds-0.82.tar.gz<\/pre>\n<p>Next we use configure and install FreeTDS with the following options:<\/p>\n<pre id=\"terminal\">.\/configure --enable-msdblib --prefix=\/usr\/local\/freetds --with-tdsver=7.0 --with-unixodbc=\/usr<\/pre>\n<pre id=\"terminal\">make<\/pre>\n<pre id=\"terminal\">make install<\/pre>\n<p>Next we need to download and uncompress the PHP source code:<\/p>\n<pre id=\"terminal\">wget http:\/\/us.php.net\/get\/php-5.3.6.tar.bz2\/from\/www.php.net\/mirror<\/pre>\n<p>Next we use configure and install PHP with the following options:<\/p>\n<pre id=\"terminal\">.\/configure  --with-mssql=\/usr\/local\/freetds --with-mysql --with-mysqli<\/pre>\n<pre id=\"terminal\">make<\/pre>\n<pre id=\"terminal\">make install<\/pre>\n<p>Lastly we will need to create and install the mssql module for PHP:<\/p>\n<pre id=\"terminal\">cd ext\/mssql<\/pre>\n<pre id=\"terminal\">phpize<\/pre>\n<pre id=\"terminal\">.\/configure --with-mssql=\/usr\/local\/freetds<\/pre>\n<pre id=\"terminal\">make<\/pre>\n<pre id=\"terminal\">make install<\/pre>\n<p>Now you should be able to connect to any Microsoft SQL (and Mysql) server from PHP using the functions found <a href=\"http:\/\/www.php.net\/manual\/en\/ref.mssql.php\" target=\"_blank\">here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently had the pleasure(!) of trying to get PHP on Debian working correctly with a Microsoft SQL server so that the data could be migrated from a Mssql instance into a Mysql one. Previous to this attempt, the developers were using a Windows machine as a &#8216;broker&#8217; between the two database. This setup was [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,3,6],"tags":[],"_links":{"self":[{"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/posts\/714"}],"collection":[{"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/comments?post=714"}],"version-history":[{"count":27,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/posts\/714\/revisions"}],"predecessor-version":[{"id":742,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/posts\/714\/revisions\/742"}],"wp:attachment":[{"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/media?parent=714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/categories?post=714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shainmiley.com\/wordpress\/wp-json\/wp\/v2\/tags?post=714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}