Welcome Guest, Not a member yet? Register   Sign In
CharacterSet mismatch
#1

We are trying to migrate to PHP 7 which involves changing the driver for the database to sqlsrv as opposed to mssql. Here is what the configuration for the database looks like:

PHP Code:
$db['default']['hostname'] = '192.168.3.55,53627';
$db['default']['username'] = '[username]';
$db['default']['password'] = '[password]';
$db['default']['database'] = "users";
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = TRUE;
$db['default']['cachedir'] = "";
$db['default']['dbcollat'] = 'sql_latin1_general_cp1_ci_as';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['char_set'] = 'utf8'

The problem is that all characters that are beyond the ASCII character set display as gibberish. With PHP 5 and the mssql driver there was an option to set the character set to 'windows-1252'. But this does not seem to be an option any more. what should the character set be? setting the character set (char_set) to 'utf8' makes it so that there are no database errors but characters are not translated correctly.
Reply
#2

The new character sets for unicode databases are defaulting to.

CHARSET = utf8mb4

COLLATE = utf8mb4_unicode_ci

You may need to alter your database and tables to change to a new character set and collation.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 09-14-2017, 06:13 AM by rkb. Edit Reason: Include more information )

(09-14-2017, 03:43 AM)InsiteFX Wrote: The new character sets for unicode databases are defaulting to.

CHARSET = utf8mb4

COLLATE = utf8mb4_unicode_ci

You may need to alter your database and tables to change to a new character set and collation.

So in essence you are saying that the charset 'windows-1252' is no longer a supported database character set.

I tried those settings 


PHP Code:
    $db['default']['dbcollat'] = 'utf8mb4_unicode_ci';
    $db['default']['char_set'] = 'utf8mb4'

and I got:


Code:
<html>
<head>
<title>Database Error</title>
<style type="text/css">

body {
background-color: #fff;
margin: 40px;
font-family: Lucida Grande, Verdana, Sans-serif;
font-size: 12px;
color: #000;
}

#content  {
border: #999 1px solid;
background-color: #fff;
padding: 20px 20px 12px 20px;
}

h1 {
font-weight: normal;
font-size: 14px;
color: #990000;
margin: 0 0 4px 0;
}
</style>
</head>
<body>
<div id="content">
<h1>A Database Error Occurred</h1>
<p>Unable to connect to your database server using the provided settings.</p><p>Filename: core/MY_DB.php</p><p>Line Number: 171</p> </div>
</body>
</html>

These don't seem to be valid options.
Reply
#4

windows-1252' is not a database character set it is a Windows browser and html character set.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(09-14-2017, 08:59 AM)InsiteFX Wrote: windows-1252' is not a database character set it is a Windows browser and html character set.

Semantics. Is all I know is that with PHP 5.x and the mssql driver I used to be able to specify 'windows-1252' as the database character set in the configuration for the database with CodeIgniter. Now (with PHP 7.x and sqlsrv driver) the database configuration for CodeIgniter no longer accepts (throws a database exception) 'windows-1252' as an option. Specifying 'windows-1252' as the database charset configuration worked before. For CodeIgniter with a sqlsrv driver this isn't a valid option.

If we want to migrate to PHP 7.x with CodeIgniter I am only asking what the database configuration charset should be to mimic the "old" behavior (with PHP 5.x and mssql driver)?
Reply
#6

(09-14-2017, 03:43 AM)InsiteFX Wrote: The new character sets for unicode databases are defaulting to.

CHARSET = utf8mb4

COLLATE = utf8mb4_unicode_ci

You may need to alter your database and tables to change to a new character set and collation.

Nobody asked anything about Unicode or UTF-8. And you're talking about MySQL on a Microsoft SQL Server issue.

(09-14-2017, 08:59 AM)InsiteFX Wrote: windows-1252' is not a database character set it is a Windows browser and html character set.

BS. A character set is a character set.
Reply
#7

(09-14-2017, 10:57 AM)rkb Wrote:
(09-14-2017, 08:59 AM)InsiteFX Wrote: windows-1252' is not a database character set it is a Windows browser and html character set.

Semantics. Is all I know is that with PHP 5.x and the mssql driver I used to be able to specify 'windows-1252' as the database character set in the configuration for the database with CodeIgniter. Now (with PHP 7.x and sqlsrv driver) the database configuration for CodeIgniter no longer accepts (throws a database exception) 'windows-1252' as an option. Specifying 'windows-1252' as the database charset configuration worked before. For CodeIgniter with a sqlsrv driver this isn't a valid option.

If we want to migrate to PHP 7.x with CodeIgniter I am only asking what the database configuration charset should be to mimic the "old" behavior (with PHP 5.x and mssql driver)?

Pretty sure I wrote a reply yesterday ... maybe I forgot to actually hit the Post button.

Read this: https://blogs.msdn.microsoft.com/brian_s...racterset/
SQLSRV_ENC_CHAR is also the default in CI if you don't specify a charset in the config.
Reply
#8

I read the link you sent (Thank you!) but it didn't say anything about 'windows-1252' Please explain why the character set specified in the database configuration for CodeIgniter 'windows-1252' worked before (PHP 5.X) and now is no longer an option.
Reply
#9

If you actually read the link, you'd know why it doesn't mention windows-1251, cp1251, etc.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB