{"id":484,"date":"2017-06-12T11:44:29","date_gmt":"2017-06-12T11:44:29","guid":{"rendered":"http:\/\/www.pawebgate.com\/blogging\/?p=484"},"modified":"2019-06-25T07:48:49","modified_gmt":"2019-06-25T07:48:49","slug":"php-ms-sql-server-greek-encoding","status":"publish","type":"post","link":"https:\/\/www.pawebgate.com\/blogging\/php-ms-sql-server-greek-encoding\/","title":{"rendered":"PHP &#8211; MS SQL Server &#8211; Greek Encoding"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-488\" src=\"https:\/\/www.pawebgate.com\/blogging\/wp-content\/uploads\/2017\/06\/timetable.png\" alt=\"timetable\" width=\"1065\" height=\"381\" srcset=\"https:\/\/www.pawebgate.com\/blogging\/wp-content\/uploads\/2017\/06\/timetable.png 1065w, https:\/\/www.pawebgate.com\/blogging\/wp-content\/uploads\/2017\/06\/timetable-300x107.png 300w, https:\/\/www.pawebgate.com\/blogging\/wp-content\/uploads\/2017\/06\/timetable-768x275.png 768w, https:\/\/www.pawebgate.com\/blogging\/wp-content\/uploads\/2017\/06\/timetable-1024x366.png 1024w, https:\/\/www.pawebgate.com\/blogging\/wp-content\/uploads\/2017\/06\/timetable-600x215.png 600w\" sizes=\"auto, (max-width: 1065px) 100vw, 1065px\" \/>This is a guide that will assist you display Greek letters while exporting data from an SQL Server Database using PHP.<\/p>\n<p>I recently had to develop an application that will show the reserved University halls according to the timetable. The data were stored in an MS SQL Server 2012 database with <strong>Greek_CI_AI<\/strong> Collation.<\/p>\n<p><!--more--><\/p>\n<p>The application uses PHP to communicate with the MS SQL Server and I spent quite a lot of time and effort to figure out how to display the Greek letters.<\/p>\n<p>The key was to use iso-8859-7 in PHP charset and utf-8 in HTML charset.<\/p>\n<p>So, the following code shows you how to implement it and enable sorting, pagination and query your data.<\/p>\n<p>&lt;?php<br \/>\nheader(&#8216;Content-Type: text\/html; charset=iso-8859-7&#8217;);<br \/>\n?&gt;<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html lang=&#8221;en&#8221;&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta charset=&#8221;utf-8&#8243;&gt;<br \/>\n&lt;link href=&#8221;..\/img\/favicon.ico&#8221; rel=&#8221;shortcut icon&#8221; type=&#8221;image\/vnd.microsoft.icon&#8221; \/&gt;<\/p>\n<p>&lt;meta name=&#8221;viewport&#8221; content=&#8221;width=device-width, initial-scale=1&#8243;&gt;<\/p>\n<p>&lt;script src=&#8221;https:\/\/code.jquery.com\/jquery-1.12.4.js&#8221;&gt;&lt;\/script&gt;<\/p>\n<p>&lt;script src=&#8221;https:\/\/cdn.datatables.net\/1.10.13\/js\/jquery.dataTables.min.js&#8221;&gt;&lt;\/script&gt;<\/p>\n<p>&lt;link href=&#8221;https:\/\/cdn.datatables.net\/1.10.13\/css\/jquery.dataTables.min.css&#8221; rel=&#8221;stylesheet&#8221;&gt;<\/p>\n<p>&lt;script src=&#8221;https:\/\/code.jquery.com\/ui\/1.12.1\/jquery-ui.js&#8221;&gt;&lt;\/script&gt;<br \/>\n&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;\/\/code.jquery.com\/ui\/1.12.1\/themes\/base\/jquery-ui.css&#8221;&gt;<\/p>\n<p>&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;css\/dynamic.css&#8221;&gt;<\/p>\n<p>&lt;script&gt;<br \/>\n$(document).ready(function() {<br \/>\n\/\/$( &#8220;#datepicker&#8221; ).datepicker();<br \/>\n\/\/ Setup &#8211; add a text input to each footer cell<br \/>\n$(&#8216;#example tfoot th&#8217;).each( function () {<br \/>\nvar title = $(this).text();<br \/>\n$(this).html( &#8216;&lt;input type=&#8221;text&#8221; placeholder=&#8221;Search &#8216;+title+'&#8221; \/&gt;&#8217; );<br \/>\n});<\/p>\n<p>\/\/ DataTable<br \/>\nvar table = $(&#8216;#example&#8217;).DataTable();<\/p>\n<p>\/\/ Apply the search<br \/>\ntable.columns().every( function () {<br \/>\nvar that = this;<\/p>\n<p>$( &#8216;input&#8217;, this.footer() ).on( &#8216;keyup change&#8217;, function () {<br \/>\nif ( that.search() !== this.value ) {<br \/>\nthat<br \/>\n.search( this.value )<br \/>\n.draw();<br \/>\n}<br \/>\n});<br \/>\n});<br \/>\n});<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;script&gt;<br \/>\n$( function() {<br \/>\n$( &#8220;#datepicker&#8221; ).datepicker({ dateFormat: &#8216;yy-mm-dd&#8217; });<br \/>\n$( &#8220;#datepicker2&#8221; ).datepicker({ dateFormat: &#8216;yy-mm-dd&#8217; });<\/p>\n<p>} );<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;script&gt;<br \/>\nfunction validateForm()<br \/>\n{<br \/>\nvar first = document.getElementById(&#8220;datepicker&#8221;).value;<br \/>\nvar last = document.getElementById(&#8220;datepicker2&#8243;).value;<\/p>\n<p>\/\/if ($.datepicker.parseDate(&#8216;dd\/mm\/yy&#8217;, GuarantyTo) &lt; $.datepicker.parseDate(&#8216;dd\/mm\/yy&#8217;, GuarantyFrom))<br \/>\nif (last &lt; first)<\/p>\n<p>{<br \/>\nalert(&#8216;End Date &#8216; + &#8216;is earlier than &#8216; + &#8216;Start Date&#8217;);<br \/>\nreturn false;<br \/>\n}<br \/>\n}<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;div class=&#8221;container-fluid&#8221;&gt;<br \/>\n&lt;div class=&#8221;row&#8221;&gt;<br \/>\n&lt;h3&gt;Timatable&lt;\/h3&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;div class=&#8221;row&#8221;&gt;<\/p>\n<p>&lt;form action=&#8221;dump.php&#8221; method=&#8221;POST&#8221; class=&#8221;form-block&#8221; onsubmit=&#8221;return validateForm()&#8221;&gt;<br \/>\n&lt;!&#8211; Form will send its results to the output file&#8211;&gt;<\/p>\n<p>&lt;div class=&#8221;field&#8221;&gt;<br \/>\n&lt;label for=&#8221;datepicker&#8221;&gt;\u0391\u03c0\u03cc: &lt;\/label&gt;<br \/>\n&lt;input type=&#8221;text&#8221; id=&#8221;datepicker&#8221; name=&#8221;datepicker&#8221;&gt;<br \/>\n&lt;!&#8211;\/div&#8211;&gt;<\/p>\n<p>&lt;!&#8211;div class=&#8221;field&#8221;&#8211;&gt;<br \/>\n&lt;label for=&#8221;datepicker2&#8243;&gt;\u0395\u03c9\u03c2: &lt;\/label&gt;<br \/>\n&lt;input type=&#8221;text&#8221; id=&#8221;datepicker2&#8243; name=&#8221;datepicker2&#8243;&gt;<br \/>\n&lt;!&#8211;\/div&#8211;&gt;<\/p>\n<p>&lt;!&#8211;div class=&#8221;field&#8221;&#8211;&gt;<br \/>\n&lt;label for=&#8221;locations&#8221;&gt;\u0391\u03af\u03b8\u03bf\u03c5\u03c3\u03b1: &lt;\/label&gt;<br \/>\n&lt;input type=&#8221;text&#8221; id=&#8221;locations&#8221; name=&#8221;locations&#8221;&gt;<\/p>\n<p>&lt;button type=&#8221;submit&#8221;&gt;Submit&lt;\/button&gt;<br \/>\n&lt;button type=&#8221;reset&#8221;&gt;Clear&lt;\/button&gt;<\/p>\n<p>&lt;\/div&gt;<br \/>\n&lt;\/form&gt;<\/p>\n<p>&lt;br \/&gt;<\/p>\n<p>&lt;table id=&#8221;example&#8221; class=&#8221;display&#8221; width=&#8221;100%&#8221; cellspacing=&#8221;0&#8243;&gt;<br \/>\n&lt;thead&gt;<br \/>\n&lt;tr&gt;<br \/>\n&lt;th&gt;\u0397\u03bc\/\u03bd\u03af\u03b1&lt;\/th&gt;<br \/>\n&lt;th&gt;\u0397\u03bc\u03ad\u03c1\u03b1&lt;\/th&gt;<br \/>\n&lt;th&gt;\u0388\u03bd\u03b1\u03c1\u03be\u03b7&lt;\/th&gt;<br \/>\n&lt;th&gt;\u039b\u03ae\u03be\u03b7&lt;\/th&gt;<br \/>\n&lt;th&gt;\u039c\u03ac\u03b8\u03b7\u03bc\u03b1&lt;\/th&gt;<br \/>\n&lt;th&gt;\u03a0\u03b5\u03c1\u03b9\u03b3\u03c1\u03b1\u03c6\u03ae&lt;\/th&gt;<br \/>\n&lt;th&gt;\u0391\u03af\u03b8\u03bf\u03c5\u03c3\u03b1&lt;\/th&gt;<br \/>\n&lt;th&gt;\u03a4\u03bf\u03c0\u03bf\u03b8\u03b5\u03c3\u03af\u03b1&lt;\/th&gt;<br \/>\n&lt;\/tr&gt;<br \/>\n&lt;\/thead&gt;<br \/>\n&lt;tfoot&gt;<br \/>\n&lt;tr&gt;<br \/>\n&lt;th&gt;\u0397\u03bc\/\u03bd\u03af\u03b1&lt;\/th&gt;<br \/>\n&lt;th&gt;\u0397\u03bc\u03ad\u03c1\u03b1&lt;\/th&gt;<br \/>\n&lt;th&gt;\u0388\u03bd\u03b1\u03c1\u03be\u03b7&lt;\/th&gt;<br \/>\n&lt;th&gt;\u039b\u03ae\u03be\u03b7&lt;\/th&gt;<br \/>\n&lt;th&gt;\u039c\u03ac\u03b8\u03b7\u03bc\u03b1&lt;\/th&gt;<br \/>\n&lt;th&gt;\u03a0\u03b5\u03c1\u03b9\u03b3\u03c1\u03b1\u03c6\u03ae&lt;\/th&gt;<br \/>\n&lt;th&gt;\u0391\u03af\u03b8\u03bf\u03c5\u03c3\u03b1&lt;\/th&gt;<br \/>\n&lt;th&gt;\u03a4\u03bf\u03c0\u03bf\u03b8\u03b5\u03c3\u03af\u03b1&lt;\/th&gt;<br \/>\n&lt;\/tr&gt;<br \/>\n&lt;\/tfoot&gt;<br \/>\n&lt;tbody&gt;<br \/>\n&lt;?php<br \/>\ninclude &#8216;database2.php&#8217;;<br \/>\nmssql_select_db(&#8216;CSTIMETABLE&#8217;)<br \/>\nor die(&#8216;Could not select a database.&#8217;);<\/p>\n<p>$sql = &#8220;SELECT evID, dayofWeek, convert(date, evstart)as res_date,CONVERT(VARCHAR(5),evstart,108) as evstart, CONVERT(VARCHAR(5),evend,108) as evend,subject, UNIEvents.evTypeID, evtypedesc, wkpattern, Locations as locations, siName from UNIEvents inner join UNIEventType on UNIEvents.evTypeID = UNIEventType.evtypeID<br \/>\ninner join UNILocation on UNIEvents.Locations = UNILocation.loName<br \/>\ninner join UNISite on UNILocation.loSiteID = UNISite.siID where evstart like &#8216;%2017%&#8217; and evID &lt; 387636 order by evID&#8221;;<\/p>\n<p>$result = mssql_query($sql)<br \/>\nor die(&#8216;A error occured: &#8216; . mysql_error());<\/p>\n<p>while ($Row = mssql_fetch_assoc($result)) {<\/p>\n<p>$mera = $Row[&#8216;dayofWeek&#8217;];<\/p>\n<p>if ($mera==1)<br \/>\n{<br \/>\n$day = &#8220;\u0394\u03b5\u03c5\u03c4\u03ad\u03c1\u03b1&#8221;;<br \/>\n}<br \/>\nif ($mera==2)<br \/>\n{<br \/>\n$day = &#8220;\u03a4\u03c1\u03af\u03c4\u03b7&#8221;;<br \/>\n}<br \/>\nif ($mera==3)<br \/>\n{<br \/>\n$day = &#8220;\u03a4\u03b5\u03c4\u03ac\u03c1\u03c4\u03b7&#8221;;<br \/>\n}<br \/>\nif ($mera==4)<br \/>\n{<br \/>\n$day = &#8220;\u03a0\u03ad\u03bc\u03c0\u03c4\u03b7&#8221;;<br \/>\n}<br \/>\nif ($mera==5)<br \/>\n{<br \/>\n$day = &#8220;\u03a0\u03b1\u03c1\u03b1\u03c3\u03ba\u03b5\u03c5\u03ae&#8221;;<br \/>\n}<br \/>\nif ($mera==6)<br \/>\n{<br \/>\n$day = &#8220;\u03a3\u03ac\u03b2\u03b2\u03b1\u03c4\u03bf&#8221;;<br \/>\n}<br \/>\nif ($mera==7)<br \/>\n{<br \/>\n$day = &#8220;\u039a\u03c5\u03c1\u03b9\u03b1\u03ba\u03ae&#8221;;<br \/>\n}<br \/>\necho &#8216;&lt;tr&gt;&#8217;;<\/p>\n<p>echo &#8216;&lt;td&gt;&#8217;. $Row[&#8216;res_date&#8217;] . &#8216;&lt;\/td&gt;&#8217;;<br \/>\necho &#8216;&lt;td&gt;&#8217;. $day . &#8216;&lt;\/td&gt;&#8217;;<br \/>\necho &#8216;&lt;td&gt;&#8217;. $Row[&#8216;evstart&#8217;] . &#8216;&lt;\/td&gt;&#8217;;<br \/>\necho &#8216;&lt;td&gt;&#8217;. $Row[&#8216;evend&#8217;] . &#8216;&lt;\/td&gt;&#8217;;<br \/>\necho &#8216;&lt;td&gt;&#8217;. $Row[&#8216;subject&#8217;] . &#8216;&lt;\/td&gt;&#8217;;<br \/>\necho &#8216;&lt;td&gt;&#8217;. $Row[&#8216;evtypedesc&#8217;] . &#8216;&lt;\/td&gt;&#8217;;<br \/>\necho &#8216;&lt;td&gt;&#8217;. $Row[&#8216;locations&#8217;] . &#8216;&lt;\/td&gt;&#8217;;<br \/>\necho &#8216;&lt;td&gt;&#8217;. $Row[&#8216;siName&#8217;] . &#8216;&lt;\/td&gt;&#8217;;<br \/>\necho &#8216;&lt;\/tr&gt;&#8217;;<br \/>\n}<br \/>\nmssql_close($link);<br \/>\n?&gt;<br \/>\n&lt;\/tbody&gt;<br \/>\n&lt;\/table&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;div class=&#8221;container&#8221;&gt;<br \/>\n&lt;div class=&#8221;row&#8221;&gt;<\/p>\n<p>&lt;\/div&gt;<br \/>\n&lt;\/div&gt;<\/p>\n<p>&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a guide that will assist you display Greek letters while exporting data from an SQL Server Database using PHP. I recently had to develop an application that will show the reserved University halls according to the timetable. The data were stored in an MS SQL Server 2012 database with Greek_CI_AI Collation.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,10],"tags":[97,96,95,98,94,57],"class_list":["post-484","post","type-post","status-publish","format-standard","hentry","category-technology","category-web-development","tag-collation","tag-encoding","tag-greek","tag-greek_ci_ai","tag-ms-sql-server","tag-php","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.pawebgate.com\/blogging\/wp-json\/wp\/v2\/posts\/484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pawebgate.com\/blogging\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pawebgate.com\/blogging\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pawebgate.com\/blogging\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pawebgate.com\/blogging\/wp-json\/wp\/v2\/comments?post=484"}],"version-history":[{"count":6,"href":"https:\/\/www.pawebgate.com\/blogging\/wp-json\/wp\/v2\/posts\/484\/revisions"}],"predecessor-version":[{"id":547,"href":"https:\/\/www.pawebgate.com\/blogging\/wp-json\/wp\/v2\/posts\/484\/revisions\/547"}],"wp:attachment":[{"href":"https:\/\/www.pawebgate.com\/blogging\/wp-json\/wp\/v2\/media?parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pawebgate.com\/blogging\/wp-json\/wp\/v2\/categories?post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pawebgate.com\/blogging\/wp-json\/wp\/v2\/tags?post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}