{"id":156,"date":"2011-04-04T15:00:53","date_gmt":"2011-04-04T15:00:53","guid":{"rendered":"http:\/\/xbmc\/wordpress\/?p=156"},"modified":"2012-02-11T00:26:57","modified_gmt":"2012-02-11T05:26:57","slug":"mysql-deleting-from-multiple-tables","status":"publish","type":"post","link":"https:\/\/xfloyd.net\/blog\/?p=156","title":{"rendered":"Connecting to MS SQL 2008 and older from PHP and Apache"},"content":{"rendered":"<p>There is a new way of doing it since PHP 3.2 after php_mssql.dll got discontinued.<br \/>\nStart by downloading this Microsoft driver for PHP <a href=\"http:\/\/sqlsrvphp.codeplex.com\/\" target=\"_blank\">http:\/\/sqlsrvphp.codeplex.com<\/a>. Read readme to determine which file(s) will match your PHP. Next copy those file to your extension folder of your PHP install, and adjust your php.ini by adding or uncommenting those two lines:<!--more--><br \/>\nextension=php_sqlsrv_53_ts_vc6.dll<br \/>\nextension=php_pdo_sqlsrv_53_ts_vc6.dll<br \/>\nThose two files were in my case, your might be different.<\/p>\n<p>At the time of writing this document MS driver was 32 bit only, so make sure your php is 32 bit as well.<\/p>\n<p>Restart apache and you should be olmost good to go, you should now see that extension under your phpinfo();<\/p>\n<p>Last step before you connect is to download<strong> <\/strong> <a href=\"http:\/\/www.microsoft.com\/download\/en\/details.aspx?displaylang=en&amp;id=16978\" target=\"_blank\">Microsoft\u00ae SQL Server\u00ae 2008 R2 Native Client <\/a>Here you have a choice of two, 32 and 64bit, you need to use one that matches the OS on which you will run the Apache on, and not the PHP architecture, which need to be 32bit anyway for this to work, that&#8217;s my experience at least.<\/p>\n<p>If you run MS SQL on the same box as the Apache and PHP then you can skip last step since MS SQL will load the native client most likely.<\/p>\n<p>PHP test example:<\/p>\n<pre>$sql_server = \"servername\";\r\n$sql_user = \"username\";\r\n$sql_pass = \"password\";\r\n$sql_db_name = \"database\";\r\n\r\n$connectionInfo = array( \"Database\"=&gt;$sql_db_name,\"UID\"=&gt;$sql_user,\"PWD\"=&gt;$sql_pass);\r\n$conn = sqlsrv_connect($sql_server,$connectionInfo);\r\nif( $conn === false ) {\r\n     die( print_r( sqlsrv_errors(), true));\r\n}\r\n\r\n$sql = 'SELECT * FROM some_table';\r\n$params = array(1, \"some data\");\r\n\r\n$result = sqlsrv_query( $conn, $sql, $params);\r\nif( $result === false ) {\r\n     die( print_r( sqlsrv_errors(), true));\r\n}\r\n\r\nwhile($row = sqlsrv_fetch_array($result))\r\n{\r\n\tprint_r($row);\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There is a new way of doing it since PHP 3.2 after php_mssql.dll got discontinued. Start by downloading this Microsoft driver for PHP http:\/\/sqlsrvphp.codeplex.com. Read readme to determine which file(s) will match your PHP. Next copy those file to your extension folder of your PHP install, and adjust your php.ini by adding or uncommenting those [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/156"}],"collection":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=156"}],"version-history":[{"count":3,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":550,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/156\/revisions\/550"}],"wp:attachment":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}