Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp Sqlserver encoding

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

like image 226
himalayantechies Avatar asked Nov 18 '13 08:11

himalayantechies


2 Answers

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
);
like image 71
himalayantechies Avatar answered Sep 24 '22 13:09

himalayantechies


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,
    ]
like image 30
mmv_sat Avatar answered Sep 24 '22 13:09

mmv_sat