Проблема с кодировкой

Обсуждение серверного программирования.

Модераторы: Duncon, Yurich

Ответить
joe
Сообщения: 3
Зарегистрирован: 03 окт 2009, 18:01

Bсем доброго дня. Опыта в программирование очень мало, и как на зло столкнулся с проблемой, нашел в глобальной сети cms она была полностью на немецком я ее перевел, сменил кодировку в бд, стояла latin1 поменял на cp1251_general_ci, но русского так и не увидел, т.е перевод отображается нормально, но при добавлении контента вместо русского пишет ðàç äâà òðè ÷åòûðå ïÿòü øåñòü ñåìü òåñò
в дб контент сохраняет примерно так àâïâàïà âïâàïâà& iuml;àâïàâï
кодировка страницы <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
Если это важно CMS E-Sports
По всей видимости в бд уже заливается не в правильной кодировки а как исправить я не знаю.
Skvor
Сообщения: 17
Зарегистрирован: 30 сен 2009, 21:14

Была у меня подобная проблема. После подключения к бд поставь. Или возможно у тебя это уже стоит, но кодировка там указана другая.

Код: Выделить всё

mysql_query('SET NAMES utf8'); 
Попробуй поставить, ну и естественно кодировку какую тебе нужно.
joe
Сообщения: 3
Зарегистрирован: 03 окт 2009, 18:01

увы стоит именно так как написали только все равно :(

Код: Выделить всё

<?php


class MyDb {
      var $mysqli;
      var $showerror = false;   // set FALSE if you don't want to see error messages
      var $showsql   = false;  // set TRUE if you want to see all SQL queries for debugging purposes
      var $sqlcounter = 0;     // counter for SQL commands
      var $rowcounter = 0;     // counter for returned SELECT rows
      var $dbtime     = 0;     // counter for time needed to execute queries
      var $starttime;

      // constructor
    function MyDb($path = "") {
        require_once($path.'inc/config.php');
        $link = @mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) OR die(mysql_error());
        mysql_select_db(MYSQL_DATABASE) OR die(mysql_error());
        mysql_query('SET NAMES utf8'); 
        if(!$link) 
        {
              $this->printerror("Sorry, no connection! (" . mysql_error() . ")");
              // you might add output for HTML code to close the page
              // here (</body></html> etc.)
              $this->mysqli = $link;
              exit();
        }
        $this->starttime = $this->microtime_float();        
      }    
    
      // destructor
      function __destruct() 
      {
          $this->close();
       }

      // explicit close
      function close() 
      {
        if($this->mysqli)
        {
              mysql_close($this->mysqli);
        }
          $this->mysqli = FALSE;
      }

      function getMysqli() 
      {
        return $this->mysqli; 
    }

      // execute SELECT query, return array
    function queryObjectArray($sql) 
    {     
        $this->sqlcounter++;
        $this->printsql($sql);
        $time1  = $this->microtime_float();
        //$result = $this->mysqli->query($sql);
        $result = mysql_query($sql);
        $time2  = $this->microtime_float();
        $this->dbtime += ($time2 - $time1);
        if($result) {
              if(mysql_num_rows($result)) 
              {
                while($row = mysql_fetch_object($result))
                 {
                      $result_array[] = $row;
                 }
                $this->rowcounter += sizeof($result_array);
                return $result_array; 
            }
             else
             {
                return FALSE;    
             }
        } 
        else 
        {
              $this->printerror(mysql_error());
              return FALSE;
        }
    }
  
    function queryMYSQL($sql) 
    {
        $this->sqlcounter++;
        $this->printsql($sql);
        $time1  = $this->microtime_float();
        $result = mysql_query($sql);
        $time2  = $this->microtime_float();
        $this->dbtime += ($time2 - $time1);
        return $result;
      }

      // execute SELECT query, return array
    function queryArray($sql) 
    {
        $this->sqlcounter++;
        $this->printsql($sql);
        $time1  = $this->microtime_float();
        $result = mysql_query($sql);
        $time2  = $this->microtime_float();
        $this->dbtime += ($time2 - $time1);
        if($result) 
        {
            if(mysql_num_rows($result)) 
              {
                while($row = mysql_fetch_array($result))
                {
                      $result_array[] = $row;
                }
                $this->rowcounter += sizeof($result_array);
            return $result_array; 
            }
              else
              {
                return FALSE;
              }
        } 
        else 
        {
            $this->printerror(mysql_error());
              return FALSE;
        }
    }


      // execute a SELECT query which returns only a single
      // item (i.e. SELECT COUNT(*) FROM table); return
      // this item
      // beware: this method return -1 for errors (not 0)!
    function querySingleItem($sql) 
    {
        $this->sqlcounter++;
        $this->printsql($sql);
        $time1  = $this->microtime_float();
        $result = mysql_query($sql);
        $time2  = $this->microtime_float();
        $this->dbtime += ($time2 - $time1);
        if($result) {
              if ($row = mysql_fetch_array($result)) 
              {
                unset($result);
                $this->rowcounter++;
                return $row[0];
              } 
              else 
              {
                // query returned no data
                return -1;
              }
        } 
        else 
        {
              $this->printerror(mysql_error());
              return -1;
        }
    }
  
  //Count Table
    function quereyCount($table,$key = "",$value = "")
      {
          if(empty($key) or empty($value))
          {
              $sql = "SELECT COUNT(*) FROM ".$table;
          }
          else
          {
              $sql = "SELECT COUNT(*) FROM ".$table." WHERE ".$key." = '".$value."'";
          }
          return $this->querySingleItem($sql);
  }

  // execute a SQL command without results (no query)
      function execute($sql) 
      {
        $this->sqlcounter++;
        $this->printsql($sql);
        $time1  = $this->microtime_float();
        $result = mysql_query($sql);
        $time2  = $this->microtime_float();
        $this->dbtime += ($time2 - $time1);
        if($result)
        {
              return TRUE;
        }
        else 
        {
              $this->printerror(mysql_error());
              return FALSE;
 .........
?>
Skvor
Сообщения: 17
Зарегистрирован: 30 сен 2009, 21:14

Код: Выделить всё

mysql_query('SET NAMES utf8'); 
Замени на:

Код: Выделить всё

mysql_query('SET NAMES cp1251'); 
И будет у тебя все хорошо ;)

Да и помещай все-таки весь код в соответствующий тэг.
joe
Сообщения: 3
Зарегистрирован: 03 окт 2009, 18:01

Все гораздо сложнее, cp1251 тоже пробывал :rolleyes:
Skvor
Сообщения: 17
Зарегистрирован: 30 сен 2009, 21:14

В phpmyadmin на прям на главной есть тип соединения с базой данных. Поиграйся там.
Ответить