Shop-Script и знаки вопроса при импорте базы MySQL

17.06.2009, рубрики: Мелочи | Теги: , , , | 14 683 комментария »

На днях позвонил человек, попросил помочь с кодировкой сайта. Сайт сделан на Shop-Script (интернет магазин). Ситуация такова, сайт хостился у одного хостинг-провайдера, теперь на другом. Был создан дамп базы данных MySQL и импортиран с той же кодировкой сравнения. Итог: вместо латинских букв, знаки вопроса. Игры с кодировками при экспорте базы и импорте успехов не принесли. Оставалось последнее действие, я был полон надежды, что оно поможет. И так, начнем.

В файле: /includes/database/mysql.php находим блок:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function db_query($s) //database query
{
$res = array();
$res["resource"] = mysql_query($s) or die( db_error()." SQL query : ".$s);
$select_keyword_index    = strpos(strtoupper($s), "SELECT");
$from_keyword_index        = strpos(strtoupper($s), "FROM");
$columns=substr( $s, $select_keyword_index + strlen("SELECT"),
$from_keyword_index - 1 - ( $select_keyword_index + strlen("SELECT") ) + 1 );
$res["columns"]=array();
$column_index = 0;
$columnArray = explode(",", $columns);
foreach($columnArray as $value)
{
if ($asIndex = strpos(strtoupper($value), "AS "))
$columnName=trim(substr($value, $asIndex+2));
else
$columnName=trim($value);
$res["columns"][$columnName] = $column_index;
$column_index++;
}
return $res;
}
[/sourcecode]

И приводим его к такому виду:

[sourcecode language='php']
function db_query($s) //database query
{
$res = array();
$res["resource"] = mysql_query($s) or die( db_error()." SQL query : ".$s);
mysql_query("SET character_set_client=cp1251");
mysql_query("SET character_set_connection=cp1251");
mysql_query("SET character_set_results=cp1251");
$select_keyword_index    = strpos(strtoupper($s), "SELECT");
$from_keyword_index        = strpos(strtoupper($s), "FROM");
$columns=substr( $s, $select_keyword_index + strlen("SELECT"),
$from_keyword_index - 1 - ( $select_keyword_index + strlen("SELECT") ) + 1 );
$res["columns"]=array();
$column_index = 0;
$columnArray = explode(",", $columns);
foreach($columnArray as $value)
{
if ($asIndex = strpos(strtoupper($value), "AS "))
$columnName=trim(substr($value, $asIndex+2));
else
$columnName=trim($value);
$res["columns"][$columnName] = $column_index;
$column_index++;
}
return $res;
}

Ура, получилось. Знаки вопросов пропали, буквы отображаются как нужно.


Comments are closed.