Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Apr 2004
    Location
    vienna
    Posts
    198
    Plugin Contributions
    9

    Default utf-8 and database connection

    in some cases when database and document charset is set to utf-8, the foreign-chars will displayed as question-marks

    a soluten could be the following code change in includes\classes\db\mysql\query_factory.php
    PHP Code:
      function connect($zf_host$zf_user$zf_password$zf_database$zf_pconnect 'false'$zp_real false) {
    //@TODO error class required to virtualise & centralise all error reporting/logging/debugging
        
    $this->database $zf_database;
        if (!
    function_exists('mysql_connect')) die ('Call to undefined function: mysql_connect().  Please install the MySQL Connector for PHP');
        if (
    $zf_pconnect != 'false') {
          
    $this->link = @mysql_connect($zf_host$zf_user$zf_passwordtrue);
        } else {
        
    // pconnect disabled ... leaving it as "connect" here instead of "pconnect"
          
    $this->link = @mysql_connect($zf_host$zf_user$zf_passwordtrue);
        }
        if (
    $this->link) {
          if (@
    mysql_select_db($zf_database$this->link)) {
            
    $this->db_connected true;
            
    /** set utf-8 database connection
                look at: http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html
                &&: http://www.adviesenzo.nl/examples/php_mysql_charset_fix/
                &&: http://de.php.net/manual/en/function.mysql-set-charset.php
            */
            
    $sql "SHOW VARIABLES LIKE 'character_set_database'";
            
    $res $this->Execute($sql);
            
    $charset $res->fields['Value'];
            
    $sql "SET NAMES $charset";
            
    $this->Execute($sql);
            return 
    true;
          } else {
            
    $this->set_error(mysql_errno(),mysql_error(), $zp_real);
            return 
    false;
          }
        } else {
          
    $this->set_error(mysql_errno(),mysql_error(), $zp_real);
          return 
    false;
        }
      } 

  2. #2
    Join Date
    Apr 2008
    Posts
    2
    Plugin Contributions
    0

    Default Re: utf-8 and database connection

    this should be really implemented, Zen Cart is one of the applications which is not able to handle MySQL encoding correctly and this little patch will fully fix it. BTW, i recommend to use "SET CHARACTER SET $charset" instead, it's much better for this.

  3. #3
    Join Date
    Apr 2004
    Location
    vienna
    Posts
    198
    Plugin Contributions
    9

    Default Re: utf-8 and database connection

    why to use SET NAMES
    look at: http://de.php.net/manual/en/function...et-charset.php message from 4.3.2008

    Using the function provided by Janez and nag worked fine for SELECTs, but with INSERT and UPDATE the non-ascii characters got converted into question marks. To fix this, I replaced SET CHARACTER SET with SET NAMES (ref: http://dev.mysql.com/doc/refman/5.0/...onnection.html). So the function becomes:

  4. #4
    Join Date
    Apr 2008
    Posts
    2
    Plugin Contributions
    0

    Default Re: utf-8 and database connection

    just read the MySQL docs here:
    http://dev.mysql.com/doc/refman/5.0/...onnection.html
    and you will understand why to use SET CHARACTER SET instead of SET NAMES (the message from php.net is stupid and not true). i'm useing SET CHARACTER SET many years without problems.

 

 

Similar Threads

  1. Question about changing database to Utf-8
    By kcb410 in forum General Questions
    Replies: 7
    Last Post: 6 Dec 2012, 03:46 PM
  2. v150 Database Setup Issue: Connection to Database failed, on iPage
    By tempoart in forum Installing on a Linux/Unix Server
    Replies: 4
    Last Post: 10 Jul 2012, 07:43 AM
  3. "Connection to Database failed" upon install - I think I need database name help
    By jasong1968 in forum Installing on a Linux/Unix Server
    Replies: 7
    Last Post: 30 Nov 2011, 10:50 AM
  4. Zen Cart with UTF-8 database
    By thewolf in forum General Questions
    Replies: 5
    Last Post: 19 Jul 2007, 12:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg