5

This has me stumped. I am trying to set encoding for my Sqlserver connection and all that I have tried has failed. I only get

Error: A Database connection using "Sqlserver" was missing or unable to connect.
The database server returned this error: SQLSTATE[IMSSP]: An invalid encoding was specified for SQLSRV_ATTR_ENCODING.

The original error I was trying to solve through encoding is:

Error: SQLSTATE[IMSSP]: An error occurred translating the query string to UTF-16: No mapping for the Unicode character exists in the target multi-byte code page.

The SQL version is 2008 R2
Cakephp Version: 2.4.2
PHP Version: 5.3.27

1
  • It seems like an error within your SQL Server try to use utf-8 instead and see if the problem persists. Commented Nov 18, 2013 at 8:57

3 Answers 3

10

After a lot of trial and error this works:

public $default = array(
    'datasource'    => 'Database/Sqlserver',
    'persistent'    => false,
    'host'      => 'localhost',
    'login'     => 'sa',
    'password'  => 'password',
    'database'  => 'SchedulingDatabase',
    'encoding'  => PDO::SQLSRV_ENCODING_UTF8
);
Sign up to request clarification or add additional context in comments.

Comments

6

Tried this out with Cakephp 3.0 seems to work nicely.

'Datasources' => [
    'default' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Sqlserver',
        'persistent' => false,
        'host' => 'localhost',
        'port' => '1433', //using this port
        'username' => 'sa',
        'password' => 'password',
        'database' => 'cake_bookmarks',
        'encoding' => PDO::SQLSRV_ENCODING_UTF8,
        'timezone' => 'UTC',
        'cacheMetadata' => true,
        'quoteIdentifiers' => false,
    ]

Comments

0

SQL 2008 doesn't support UTF-16 only SQL 2012

http://msdn.microsoft.com/en-us/library/ms143726(v=sql.110).aspx

UTF-8 isn't supported at all by MS SQL.

1 Comment

So sad ;_;, use mysql or postgres.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.