mssql, cp1251

Questionsmssql, cp1251
Yaroslav asked 8 years ago

Hello!

I use PHP Grid with mssql by ADO with this method:
$db_conf = array();
$db_conf["type"] = "ado_mssql";
$db_conf["server"] = "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER=*;DATABASE=*;UID=*;PWD=*d;";
$db_conf["user"] = null;
$db_conf["password"] = null;
$db_conf["database"] = null;

But almost all columns (and their fields) in DB are in 1251 (russian), and not UTF-8.
So I have to use iconv to connect, like this:

$unumber = iconv('UTF-8','CP1251','Учетный_номер');
$g->table = $klasstp;

Also, I cant make ->select_command, becouse mssql want CP1251, and standart command give it 1251

And, more umportant, PHPgrid doesnt want to show data in cp1251, so I left only with english named columns.

Sorry for lack of proper English.

I am using old 1.4.8 version of Grid, which was left by guy, who worked before me. Is this feature work in 2.0, or this is a matter of char_set configuration ?

6 Answers
Abu Ghufran answered 8 years ago

I have not tested this case but few clients uses mb_convert_encoding function:
e.g.
$unumber = mb_convert_encoding('Учетный_номер', "UTF-8","CP1251");

and to display in grid ..

$e["on_data_display"] = array("filter_display", null, true);
$g->set_events($e);

function filter_display($data)
{
foreach($data["params"] as &$d)
{
foreach($d as $k=>$v)
$d[$k] = mb_convert_encoding($d[$k], "UTF-8","CP1251");
}
}

Reply back if still not resolved.

Yaroslav answered 8 years ago

Thank you for solution, but it didn't do the trick.

I used your solution, and got error:
{"page":"1","total":1,"records":6,"rows":[{"ID1":"1",null:"u0413u041fu042du0421 u043cu043eu0440u0441u043au043eu0433u043e …. 4f"},{"ID1":"2",null:"u … etc.

Which is nice, because before I use your function i got error like:
{"page":"1","total":1,"records":6,"rows":[{"ID1":"1",null:null,null:null},{"ID1":"2",null:null,null:null}, etc…

So DB give me my data, but coding is still wrong (i think?), and grid is empty

Also, when your grid make changes to DB, will it try to send it UTF-8?

{
$stable = mb_convert_encoding('ЭЛЕКТРОСТАНЦИЯ_Т',"CP1251","utf-8");
$sname = mb_convert_encoding('Наименование_ТП',"CP1251","utf-8");
$splace = mb_convert_encoding('Местоположение',"CP1251","utf-8");

$g->table = $stable;
$g->select_command = "SELECT ID1, $sname, $splace FROM $stable WHERE id1<10 ";

$e["on_data_display"] = array("filter_display", null, true);
$g->set_events($e);

$col = array();
$col["title"] = "Id";
$col["name"] = "ID1";
$cols[] = $col;

$col = array();
$col["title"] = "Наименование";
$col["name"] = mb_convert_encoding('Наименование_ТП', "UTF-8","CP1251");
$cols[] = $col;

$g->set_columns($cols);

$out = $g->render("list1");
}

Yaroslav answered 8 years ago

I think the problem is that col.name wont store cp1251 value. I think I need to fetch rows from sql and save them in cp1251, somewhere in @function set_columns, right now it saves all CP1251 cols as null

Abu Ghufran answered 8 years ago

Yes, that's my conclusion too.
You can rename field name to plain text to work in grid.

Yaroslav answered 8 years ago

Sorry, I didn't understand you.

You mean change source DB field names? I am afraid I can't do that

Or, you suggest to use something like strip_tags?

Abu Ghufran answered 8 years ago

Hello,

Currently grid uses these database field names in JS code and it should be plain english text.
Special non-en character are not supported.

If this was working in older version, please email me the working version of lib/inc/jqgrid_dist.php and i'll try to merge changes.

Your Answer

5 + 19 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?