D
D
Denis Demin2019-10-16 17:12:34
PHP
Denis Demin, 2019-10-16 17:12:34

How to write data via php to MS SQL database (not MySQL) in windows-1251 encoding?

There is a form of recording in the database, of course, there is also code that almost successfully implements this, but not in the correct encoding.
Who can help?

<?php
require 'db.php';

$id = $_POST['id'];
$reason = $_POST['reason'];
$comment = $_POST['comment'];
$approve_name = $_POST['approve_name'];
$appr = $_POST['appr'];

print_r($_POST);

if($reason != '') {
$upd_data = $DBH->prepare("SET NAMES cp1251; UPDATE SCUD2 SET reason=:reason, comment=:comment WHERE SCUDID=:id");
$upd_data->execute(array(
          'id'=>$id,
          'reason'=>$reason,
          'comment'=>$comment,
          ));
}

if($approve_name != '') {
  if($appr == '') {
    $approve_name = '';
  }
$upd_data = $DBH->prepare("SET NAMES cp1251; UPDATE SCUD SET state=:state, approve_name=:approve_name WHERE SCUDID=:id");
$upd_data->execute(array(
          'id'=>$id,
          'state'=>$appr,
          'approve_name'=>$approve_name,
          ));
}
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adamos, 2019-10-16
@neytrino-kain

php.net/manual/en/function.iconv.php

F
FanatPHP, 2019-10-16
@FanatPHP

set names does not set the target encoding, but the source
one. You don't need to specify the target one, the base already knows it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question