{"id":375,"date":"2019-08-19T14:52:24","date_gmt":"2019-08-19T13:52:24","guid":{"rendered":"https:\/\/blogs.gre.ac.uk\/cmssupport\/?page_id=375"},"modified":"2019-08-19T14:52:24","modified_gmt":"2019-08-19T13:52:24","slug":"connecting-to-sql-server-using-php","status":"publish","type":"page","link":"https:\/\/blogs.gre.ac.uk\/cmssupport\/application-development\/programming\/php\/connecting-to-sql-server-using-php\/","title":{"rendered":"Connecting to SQL Server using PHP"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The following lines of code can be used to connect to the SQL Server. Please note you can only connect to SQL Server from PHP code on stuiis.cms.gre.ac.uk web server, and NOT from stuweb.cms.gre.ac.uk:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$serverName = \"SQL-SERVER\"; \n$connectionInfo = array( \"Database\"=&gt;\"username\");\n$conn = sqlsrv_connect( $serverName, $connectionInfo);\n\n$rs = $conn-&gt;Execute(\"SELECT * FROM account\"); \n\nwhile (!$rs-&gt;EOF) { \n$fv = $rs-&gt;Fields(\"account_description\"); \necho \"ID: \".$fv-&gt;value.\"\\n\"; \n$rs-&gt;MoveNext(); \n} \n\n$rs-&gt;Close();<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following lines of code can be used to connect to the SQL Server. Please note you can only connect to SQL Server from PHP code on stuiis.cms.gre.ac.uk web server, and NOT from stuweb.cms.gre.ac.uk: $serverName &hellip;<\/p>\n","protected":false},"author":53,"featured_media":0,"parent":122,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"footnotes":""},"class_list":["post-375","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":0,"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages\/375\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/pages\/122"}],"wp:attachment":[{"href":"https:\/\/blogs.gre.ac.uk\/cmssupport\/wp-json\/wp\/v2\/media?parent=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}