I am connecting to an MS SQL server with PDO using the sqlsrv driver.
PHP version is 5.3.24. The working connection looks like this:
$dsny = "sqlsrv:Server=xx1;Database=xx2";
$usery = 'xx3';
$passwordy = 'xx4';
$dbhy = new PDO($dsny, $usery, $passwordy);
**
But i need to set characters, and then i try this:
$dsny = "sqlsrv:Server=xx1;Database=xx2;charset=utf8";
$usery = 'xx3';
$passwordy = 'xx4';
$dbhy = new PDO($dsny, $usery, $passwordy);
When i add the charset i get this error: "Fatal error: Uncaught exception 'PDFException' with message 'SQLSTATE[IMSSP]: An invalid keyword 'charset' was specified in the dsn string'"
So what could be causing this fault ?
From what i read i need to do like this since i am running a new PHP version.
You need to apply the attribute after connecting:
$dbhy->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_UTF8);
See: https://msdn.microsoft.com/en-us/library/ff628157(v=sql.105).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With