PDA

View Full Version : سوال: مشکل در نمایش فونت فارسی از دیتا بیس



hamed-php
سه شنبه 16 خرداد 1391, 08:38 صبح
با سلام برای تابع زیر چگونه میتوان فونت فارسی رو تعریف کرد؟




function simpleQuery($query)
{
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
$query = $this->modifyQuery($query);
if ($this->_db) {
if (!@mysql_select_db($this->_db, $this->connection)) {
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
}
}
if (!$this->autocommit && $ismanip) {
if ($this->transaction_opcount == 0) {

$result = @mysql_query('SET AUTOCOMMIT=0', $this->connection);
$result = @mysql_query('BEGIN', $this->connection);


}

}
if (!$this->options['result_buffering']) {
$result = @mysql_unbuffered_query($query, $this->connection);
} else {
$result = @mysql_query($query, $this->connection);
}

}


اضافه میکنم که تابع فوق بخشی از یک کلاس میباشد که در فایل ضمیمه قرار داده ام. مربوط به
PEAR
87902

MMSHFE
سه شنبه 16 خرداد 1391, 16:30 عصر
function simpleQuery($query) {
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
$query = $this->modifyQuery($query);
if ($this->_db) {
if (!@mysql_select_db($this->_db, $this->connection)) {
@mysql_query('SET NAMES \'utf8\'');
@mysql_set_charset('utf8');
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
}
}
if (!$this->autocommit && $ismanip) {
if ($this->transaction_opcount == 0) {
$result = @mysql_query('SET AUTOCOMMIT=0', $this->connection);
$result = @mysql_query('BEGIN', $this->connection);
}
}
if (!$this->options['result_buffering']) {
$result = @mysql_unbuffered_query($query, $this->connection);
}
else {
$result = @mysql_query($query, $this->connection);
}
}

موفق باشید.

hamed-php
سه شنبه 16 خرداد 1391, 17:21 عصر
با سلام

ممنون از پاسخ شما. اما متاسفانه نمیدونم چرا همچنان فونتهای فارسی درون دیتا بیس رو که فرامیخونم به این شکل به نمایش درمیاد:
���� �

آیا ممکنه که اشکال از این تابع باشد؟


function dataSource($db_handl, $sql = "", $start_order = "", $start_order_type = ""){
// clear sql statment
$sql = str_replace("\n", " ", $sql); // new row
$sql = str_replace(chr(13), " ", $sql); // CR sign
$sql = str_replace(chr(10), " ", $sql); // LF sign
$sql = str_replace(";", "", $sql);

// get preliminary Primary Key
$p_key = explode(" ", $sql);
$p_key = str_replace(",", "", $p_key[1]);
$p_key = explode(".", $p_key);
$this->primary_key = $p_key[count($p_key)-1];

$req_sort_field = $this->getVariable('sort_field');
$req_sort_field_by = $this->getVariable('sort_field_by');
$sort_field = ($req_sort_field_by != "") ? $req_sort_field_by : $req_sort_field ;
$req_sort_type = $this->getVariable('sort_type');
$this->db_handler = $db_handl;
$this->db_handler->setFetchMode(DB_FETCHMODE_ORDERED);

// handle SELECT SQL statement
$this->sql_view = $sql;
if($this->lastSubStrOccurence($this->sql_view, "from ") < $this->lastSubStrOccurence($this->sql_view, "where ")){
// handle SELECT statment with sub-SELECTs and SELECT without WHERE
$ind = strpos(strtolower($this->sql_view), "group by");
if($ind){
$prefix = substr($sql, 0, $ind);
$suffix = substr($sql, $ind);
$this->sql_view = $prefix." ";
$this->sql_group_by = $suffix;
}else{
$this->sql_view .= " WHERE 1=1 ";
}
}else if($this->lastSubStrOccurence($this->sql_view, "where ") == ""){
$this->sql_view .= " WHERE 1=1 ";
}else{
$ind = strpos(strtolower($this->sql_view), "group by");
if($ind){
$prefix = substr($sql, 0, $ind);
$suffix = substr($sql, $ind);
$this->sql_view = $prefix." ";
$this->sql_group_by = $suffix;
}
}
$this->sql = $this->sql_view.$this->sql_group_by;

// set default order
if($start_order != ""){
$default_sort_field = explode(",", $start_order);
$default_sort_type = explode(",", $start_order_type);
for($ind=0; $ind < count($default_sort_field); $ind++){
$this->default_sort_field[$ind] = trim($default_sort_field[$ind]);
if(isset($default_sort_type[$ind])){
if((strtolower(trim($default_sort_type[$ind])) == "asc") || (strtolower(trim($default_sort_type[$ind])) == "desc")){
$this->default_sort_type[$ind] = trim($default_sort_type[$ind]);
}else{
$this->default_sort_type[$ind] = "ASC";
$this->addWarning('$default_order_type', $start_order_type);
}
}else{
$this->default_sort_type[$ind] = "ASC";
}
}
}else{
$this->default_sort_field[0] = "1";
$this->default_sort_type[0] = "ASC";
}
// create ORDER BY part of sql statment
if($req_sort_field){
if(!substr_count($this->sql, "ORDER BY")){
$this->sql_sort = " ORDER BY ".$sort_field." ".$req_sort_type;
}else{
$this->sql_sort = " , ".$sort_field." ".$req_sort_type;
}
}else if($start_order != ""){
$this->sql_sort = " ORDER BY ".$this->getOrderByList();
}else{
$this->sql_sort = " ORDER BY 1 ASC";
}

$this->getDataSet($this->sql_sort);

// check if the preliminary key is a Primary Key
if(strtolower($this->getFieldInfo(0, 'type', 1)) != "int"){
$this->addWarning($this->primary_key, "Check this field carefully, it may be not a Primary Key!");
}
}




$db_conn = DB::factory('mysql');

$result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));

if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }




function &factory($type, $options = false)
{

if (!is_array($options)) {
$options = array('persistent' => $options);
}

if (isset($options['debug']) && $options['debug'] >= 2) {
// expose php errors with sufficient debug level
include_once PEAR_DIR . "DB/{$type}.php";
} else {
@include_once PEAR_DIR . "DB/{$type}.php";
}

$classname = "DB_${type}";

if (!class_exists($classname)) {
$tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
"Unable to include the DB/{$type}.php file",
'DB_Error', true);
return $tmp;
}

$obj = new $classname;

foreach ($options as $option => $value) {
$test = $obj->setOption($option, $value);
if (DB::isError($test)) {
return $test;
}
}

return $obj;
}

MMSHFE
سه شنبه 16 خرداد 1391, 18:16 عصر
نه ایراد از تابع نیست. احتمالاً کدگذاری فایلتون درست نیست چون اگه مشکل از تابع باشه باید ? بیاد. الآن داره یونیکد میخونه. احتمالاً فایلتون با کدگذاری UTF-8 without BOM ذخیره نشده یا تگ meta رو نگذاشتین. دقت کنید که تگ meta با کدگذاری utf-8 توی فایلی که با کدگذاری ANSI ذخیره شده باشه درست کار نمیکنه.

behzadkhatari
سه شنبه 16 خرداد 1391, 19:05 عصر
نوع فیلد را در دیتابیس utf8_general_ci بذارید

hamed-php
سه شنبه 16 خرداد 1391, 19:05 عصر
با سلام

دقیقاً کدوم فایلها رو باید این تنظیمات رو روش انجام بدهم
من تقریباً همه فایلهای php رو بصورت UTF-8 without BOM ذخیره کردم و یک تگ meta هم قبل از کد php گذاشتم!

اما هنوز نتونستم این ���� رو به شکل درست دربیارم

hamed-php
سه شنبه 16 خرداد 1391, 19:08 عصر
نوع فیلد را در دیتابیس utf8_general_ci بذارید
فرقی نکرد با تغییر utf8_general_ci

colors
سه شنبه 16 خرداد 1391, 19:12 عصر
درود

در دیتابایس به صورت صحیح ( پارسی ) ذخیره شده اند؟

hamed-php
سه شنبه 16 خرداد 1391, 19:20 عصر
درود

در دیتابایس به صورت صحیح ( پارسی ) ذخیره شده اند؟
بلی کاملاً صحیح پارسی

colors
سه شنبه 16 خرداد 1391, 19:25 عصر
این رو یه تست کنید

function simpleQuery($query)
{
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
$query = $this->modifyQuery($query);
if ($this->_db) {
if (!@mysql_select_db($this->_db, $this->connection)) {
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
}
}
if (!$this->autocommit && $ismanip) {
if ($this->transaction_opcount == 0) {

$result = @mysql_set_charset("utf8", $this->connection);
$result = @mysql_query('BEGIN', $this->connection);


}

}
if (!$this->options['result_buffering']) {
$result = @mysql_unbuffered_query($query, $this->connection);
} else {
$result = @mysql_set_charset("utf8", $this->connection);
$result = @mysql_query($query, $this->connection);
}

}

hamed-php
سه شنبه 16 خرداد 1391, 19:34 عصر
این رو یه تست کنید
----
تست کردم ولی جواب نداد

colors
سه شنبه 16 خرداد 1391, 19:41 عصر
خروجیت از اون توبعی که در پست شماره 3 گذاشتی عبور میکنن؟

hamed-php
سه شنبه 16 خرداد 1391, 19:49 عصر
خروجیت از اون توبعی که در پست شماره 3 گذاشتی عبور میکنن؟
خوب البته حروف لاتین و اعداد رو مشکلی ندارم
و صحیح درج میشن چه در دیتابیس و چه در خروجی
منظورتون از خروجی چیز دیگه ای هست؟

colors
سه شنبه 16 خرداد 1391, 19:53 عصر
خروجی که برای چاپ میفرستی.

دخالت اون توابع رو از بین ببر ببین درست میشه؟

بخصوص این تابع رو


function dataSource($db_handl, $sql = "", $start_order = "", $start_order_type = ""){
// clear sql statment
$sql = str_replace("\n", " ", $sql); // new row
$sql = str_replace(chr(13), " ", $sql); // CR sign
$sql = str_replace(chr(10), " ", $sql); // LF sign
$sql = str_replace(";", "", $sql);

// get preliminary Primary Key
$p_key = explode(" ", $sql);
$p_key = str_replace(",", "", $p_key[1]);
$p_key = explode(".", $p_key);
$this->primary_key = $p_key[count($p_key)-1];

$req_sort_field = $this->getVariable('sort_field');
$req_sort_field_by = $this->getVariable('sort_field_by');
$sort_field = ($req_sort_field_by != "") ? $req_sort_field_by : $req_sort_field ;
$req_sort_type = $this->getVariable('sort_type');
$this->db_handler = $db_handl;
$this->db_handler->setFetchMode(DB_FETCHMODE_ORDERED);

// handle SELECT SQL statement
$this->sql_view = $sql;
if($this->lastSubStrOccurence($this->sql_view, "from ") < $this->lastSubStrOccurence($this->sql_view, "where ")){
// handle SELECT statment with sub-SELECTs and SELECT without WHERE
$ind = strpos(strtolower($this->sql_view), "group by");
if($ind){
$prefix = substr($sql, 0, $ind);
$suffix = substr($sql, $ind);
$this->sql_view = $prefix." ";
$this->sql_group_by = $suffix;
}else{
$this->sql_view .= " WHERE 1=1 ";
}
}else if($this->lastSubStrOccurence($this->sql_view, "where ") == ""){
$this->sql_view .= " WHERE 1=1 ";
}else{
$ind = strpos(strtolower($this->sql_view), "group by");
if($ind){
$prefix = substr($sql, 0, $ind);
$suffix = substr($sql, $ind);
$this->sql_view = $prefix." ";
$this->sql_group_by = $suffix;
}
}
$this->sql = $this->sql_view.$this->sql_group_by;

// set default order
if($start_order != ""){
$default_sort_field = explode(",", $start_order);
$default_sort_type = explode(",", $start_order_type);
for($ind=0; $ind < count($default_sort_field); $ind++){
$this->default_sort_field[$ind] = trim($default_sort_field[$ind]);
if(isset($default_sort_type[$ind])){
if((strtolower(trim($default_sort_type[$ind])) == "asc") || (strtolower(trim($default_sort_type[$ind])) == "desc")){
$this->default_sort_type[$ind] = trim($default_sort_type[$ind]);
}else{
$this->default_sort_type[$ind] = "ASC";
$this->addWarning('$default_order_type', $start_order_type);
}
}else{
$this->default_sort_type[$ind] = "ASC";
}
}
}else{
$this->default_sort_field[0] = "1";
$this->default_sort_type[0] = "ASC";
}
// create ORDER BY part of sql statment
if($req_sort_field){
if(!substr_count($this->sql, "ORDER BY")){
$this->sql_sort = " ORDER BY ".$sort_field." ".$req_sort_type;
}else{
$this->sql_sort = " , ".$sort_field." ".$req_sort_type;
}
}else if($start_order != ""){
$this->sql_sort = " ORDER BY ".$this->getOrderByList();
}else{
$this->sql_sort = " ORDER BY 1 ASC";
}

$this->getDataSet($this->sql_sort);

// check if the preliminary key is a Primary Key
if(strtolower($this->getFieldInfo(0, 'type', 1)) != "int"){
$this->addWarning($this->primary_key, "Check this field carefully, it may be not a Primary Key!");
}
}

hamed-php
سه شنبه 16 خرداد 1391, 20:23 عصر
[QUOTE=colors;1520356]خروجی که برای چاپ میفرستی.

دخالت اون توابع رو از بین ببر ببین درست میشه؟

بخصوص این تابع رو
----

بلی امتحان کردم بصورت خیلی ساده این تابع رو درآوردم. اما بازهم تغییری نکرد

hamed-php
سه شنبه 16 خرداد 1391, 20:26 عصر
پیشنهادات ذکر شده در این لینک رو هم بکار گرفتم اما فایده ای نداشت
http://marc.info/?l=nyphp-talk&m=133780236910315&w=2

البته بجز این دو قسمت که نمیدونم چی هست


#httpd.conf AddDefaultCharset UTF-8 <VirtualHost> AddCharset UTF-8 .htm </VirtualHost>

behzadkhatari
سه شنبه 16 خرداد 1391, 23:14 عصر
حتما باید دستور زیر رو بلافاصله بعد از کانکت شدن به دیتابیس قراربدید
mysql_query("SET NAMES "utf8");

colors
چهارشنبه 17 خرداد 1391, 08:36 صبح
قبلا یکی دوبار با مشکل نمایش محتویات فارسی به این صورت برخورده بودم ( ���� � ) و این مشکل رو تابع substr واسم به وجود میاورد. یه صفحه خام درست کن و دستی به بانک وصل شو اطلاعات بانک رو چاپ کن ببین بازم این مشکل رو داره

saeidpsl
چهارشنبه 17 خرداد 1391, 14:39 عصر
با سلام

در تیبل sql
ENGINE رو بزار
ENGINE=InnoDB DEFAULT CHARSET=utf8;
مثل این




CREATE TABLE IF NOT EXISTS `test` (

) ENGINE=InnoDB DEFAULT CHARSET=utf8;





اینم دو فایل php
http://www.uploadbaz.com/qdsw8t50pw04
که با فارسی سازگاره و با utf8 ذخیره شده.

یکیش config و یکیش هم برای تست

موفق باشی:چشمک: