0

enter image description here

When reading and displaying data which is in cyrilic from a Microsoft SQL Server, PHP fails to display it correctly. You can see part of the text displayed (only the non cyrilic stuff)

Here is what I have tried:

  • setting the values in the table nchar, varchar, text and char
  • adding a utf-8 tag in the html code
  • using the PHP driver for SQL with the ODBC driver
  • tried these collations: Cyrillic_General_100_CI_AI_SC_UTF8, cyrillic general with utf-8 and the windows code page (1251) with cyrillic general

enter image description here

enter image description here

<html>
<style>
table { width: 20em; border-collapse: collapse; }

th {
  border-bottom: 2px solid #000;
  padding: 0.5em 0 0.1em 0;
  font-size: 1.2em;
}

td {
  border-bottom: 2px solid #ccc;
  padding: 0.5em 0 0.1em 0;
}

th:nth-child(n + 2),
td:nth-child(n + 2) {
  text-align: center;
}

[data-has-link="no"]    { background-color: #F77; }
[data-has-link="yes"]   { background-color: #7F7; }


#score, #name {  width: 50%; }
</style>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="jo.js"></script>
<title>AV.31.U</title>
</head>

<body>
<table style="width: 100%; height:50%" border="1" cellpadding="3">
<caption>AV.31.U</caption>
  <thead>
<tr>
            <td><div id="current_date"></p>
<script>
$(function() {
  var $table = $('table');
  $table.find('#current_date').text(getCurrentDate());
  colorRows($table); // Color the rows!
});

function getCurrentDate () {
  return new Date().toLocaleDateString('en-GB', {
    year: 'numeric',
    month: 'numeric',
    day: 'numeric'
  });
}

function colorRows($table) {
  var hasLink;
  $table.find('tbody > tr').each(function(rowIndex) {
    const $row = $(this);
    $row.find('td').each(function(colIndex) {
      const $cell = $(this).removeAttr('data-has-link');
      const cellValue = $cell.text().trim();
      if (isFinite(cellValue)) {
        // Color cell based on individual data
        const hasLink = cellHasLink(parseInt(cellValue, 10));
        if (hasLink !== 'maybe') {
          $cell.attr('data-has-link', hasLink);
        }
      }
    });
    // Color row based on 7th column
    var i = parseInt($row.find('td:nth-child(7)').text(), 10);
    $row.attr('data-has-link', cellHasLink(i));
  });
}

function cellHasLink(value) {
  switch (value) {
    case 0  : return 'no';
    case 1  : return 'yes';
    default : return 'maybe';
  }
}
</script></td>
    <td colspan="6">Home</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <th>Наименование</th>
      <th>Описание</th>
      <th>Версия</th>
      <th>Верс. опис.</th>
      <th>Модел</th>
      <th>Видео</th>
      <th>Видео отвори</th>
      <th>Снимк.</th>
      <th>Снимк. отвори</th>
      <th>Специф.</th>
      <th>Специф. отвори</th>
    </tr>
  </thead>
  <tbody>
    <tr>
<?php
$username = 'censored';
$password = 'censored';
$servername = 'censored';
$database = 'SQL_KASI';
ini_set('display_errors', '1');
error_reporting(E_ALL);

$db = odbc_connect("Driver={SQL Server};Server=$servername;Database=$database;", $username, $password) or die ("could not connect<br />");

$stmt = "Select * from machine_vertical";
$result = odbc_exec($db, $stmt);

if ($result == FALSE) die ("could not execute statement $stmt<br />");

while (odbc_fetch_row($result)) // while there are rows
{
    print "<tr>\n";
    print "  <td>" . odbc_result($result, "mach_name") . "\n";
    print "  <td>" . odbc_result($result, "mach_descr") . "\n";
    print "  <td>" . odbc_result($result, "mach_version") . "\n";
    print "  <td>" . odbc_result($result, "mach_version_descr") . "\n";
    print "  <td>" . odbc_result($result, "mach_model") . "\n";
    print "  <td>" . odbc_result($result, 'mach_video_yn') . "\n";
    print "  <td>" . odbc_result($result, "mach_video_open") . "\n";
    print "  <td>" . odbc_result($result, "mach_pic_yn") . "\n";
    print "  <td>" . odbc_result($result, 'mach_pic_open') . "\n";
    print "  <td>" . odbc_result($result, "mach_spec_yn") . "\n";
    print "  <td>" . odbc_result($result, "mach_spec_open") . "\n";
    print "</tr>\n";
}

odbc_free_result($result);
odbc_close($db);
?>
</tr>
</tbody>
</table>
</body>
</html>

9
  • I don't have enough experience with the odbc PHP extension, but in a similar situation (storing and retrieving bulgarian text data), I use the PHP Driver for SQL Server. Commented Oct 11, 2022 at 5:44
  • Do you happen to know how to install it? I cannot find instructions anywhere. Commented Oct 11, 2022 at 5:53
  • You may try to start from here. Commented Oct 11, 2022 at 5:56
  • I configured the stuff but it still does not work Commented Oct 11, 2022 at 6:26
  • Can you edit the question with the current attempt (using PHP Driver for SQl Server) and additional information about the mach_descr column collation? Commented Oct 11, 2022 at 6:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.