ProjectNami / projectnami

WordPress powered by Microsoft SQL Server
http://projectnami.org
Other
270 stars 138 forks source link

Special characters not showing correct #303

Open CaroeK opened 6 years ago

CaroeK commented 6 years ago

Hi again. I'm using local installed SQL Express. In my cumstom PHP pages the special characters (æ ø å) are shown as som weird signs. I have tried a lot of different stuff in PHP and in HTMl, but nothing changes this. Selecting them in Management studio shown the correct characters. If found som old posts here about it, but I don't know where the problem is. Is it in MSSQL (I use the collation Danish_Norwegian_CI_AS and nvarchar), or in my custom PHP or the projectnami wordpress installation? In wordpress I have select the Danish language and when I create a normal page in wordpress it can show the special characters. It only in my custom PHP it doesn't work. Can you provide me with som help please :)

CaroeK commented 6 years ago

I tried to change the following

if ( getenv('ProjectNami.UTF8') ) { $this->dbh = sqlsrv_connect( $this->dbhost, array( "Database"=> $this->dbname, "UID"=> $this->dbuser, "PWD"=> $this->dbpassword, 'ReturnDatesAsStrings'=>true, 'MultipleActiveResultSets'=> false, 'CharacterSet'=> 'UTF-8') ); } else { $this->dbh = sqlsrv_connect( $this->dbhost, array( "Database"=> $this->dbname, "UID"=> $this->dbuser, "PWD"=> $this->dbpassword, 'ReturnDatesAsStrings'=>true, 'MultipleActiveResultSets'=> false, 'CharacterSet'=> 'UTF-8') ); } in wp-db.php

Then my custom PHP works and shows the correct characters, but the WordPress it self shows the wrong characters now. Maybe it helps you helping me. I don't get it.

patrickebates commented 6 years ago

So two possibilities. First, if your own tables are using datatypes of char or varchar rather than nchar or nvarchar, that could be contributing to the issue you are seeing.

Second, regarding the forcing of UTF-8 charset. It has to be enabled before beginning the install or the posts and pages added before setting it become unusable. It might even cause some issues with site options and similar settings.

CaroeK commented 6 years ago
  1. I found the issues about varchar and nvarchar, so i dropped and recreated the table with nvarchar. Then I filled in the data again. So that should not be the problem.
  2. Okay, so I have to do the installation from scratch. No problem, but I don't know exactly where I have to change the setting? I use xampp with apache on Windows 10. Can you provide me with at precise place to enable it? Thanks very much for your help.
patrickebates commented 6 years ago

I'm not fully versed with Apache, but do you have a location where you can set custom environment variables for PHP? Maybe a user.ini or just go in and add something to the php.ini directly?

In the code you posted above

if ( getenv('ProjectNami.UTF8') ) {

So if you set ProjectNami.UTF8 = 1 somewhere, that will force UTF-8 connections from now on and persist through code updates.

CaroeK commented 6 years ago

I can change the PHP.ini.

  1. Can I just put ProjectNami.UTF8 = 1; Somewhere in the php.ini ?
  2. I still have to reinstall the WordPress site right?
patrickebates commented 6 years ago

1) That might work, not 100% certain. I have done it through IIS and Azure app settings myself.

2) Yes

CaroeK commented 6 years ago

Damn....just tried.... wasn't enough.... no change :(

patrickebates commented 6 years ago

Looks like it needs to be set at the Apache INI level or maybe .htaccess

https://stackoverflow.com/questions/10902433/setting-environment-variables-for-accessing-in-php

http://www.smorgasbork.com/2017/10/20/apache-php-environment-variables/

patrickebates commented 6 years ago

And see https://httpd.apache.org/docs/2.4/mod/mod_env.html#setenv

CaroeK commented 6 years ago

Thank you for super fast and very helpfull help 🥇 I modified the C:\xampp\apache\conf\extra\httpd-xampp.conf file and added the last line in this section:

SetEnv MIBDIRS "C:/xampp/php/extras/mibs" SetEnv MYSQL_HOME "\\xampp\\mysql\\bin" SetEnv OPENSSL_CONF "C:/xampp/apache/bin/openssl.cnf" SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php" SetEnv PHPRC "\\xampp\\php" SetEnv TMP "\\xampp\\tmp" **SetEnv ProjectNami.UTF8 "1"**

Then I reinstalled WordPress and now it works. Thanks.

srutzky commented 3 years ago

@CaroeK (and @patrickebates ): I'm guessing that this issue has been fully resolved via #422 . Unless it was an entirely different issue. Reading through the comments it appears that this issue deals mostly with configuration (i.e. proper setting of ProjectName.UTF8 ), However, it might not have been possible to confirm the fix recommend above without #422 in place (even if the example "special" characters shown in the initial post worked as of the last comment on 2018-08-31, that doesn't mean that other "special" characters, such as "𒂭" work). @CaroeK , can you please confirm that this is fully resolved and close it out, or confirm that characters such as "𒂭" do not work, in which case this can probably still be closed referencing #422 which ultimately will fix that remaining issue (which I suspect is the case as I don't see how "𒂭" could save correctly without the update provide in #422).

Thanks and take care, Solomon..