I'm trying to build a script PHP to integrate with the Nette Database.
I'm using SQLSRV driver to connect to MS SQL database.
Using the SQLSRV library directly, I can pass the option “CharacterSet” in the information for the connection like in this example:
$this->CONNECTION = sqlsrv_connect(‘IP’, array(
‘UID’ ⇒ ‘username’,
‘PWD’ ⇒ ‘password’,
‘Database’ ⇒ ‘db name’,
‘CharacterSet’ ⇒ ‘UTF-8’
)) or die(sqlsrv_errors());
Instead, using PDO I must set an attribute like in this example:
$dsny = “sqlsrv:Server=xx1;Database=xx2”;
$usery = ‘xx3’;
$passwordy = ‘xx4’;
$dbhy = new PDO($dsny, $usery, $passwordy);
Using the Nette Database (that use PDO), how I can set this attribute?
Thanks a lot.
Hello, sure, and do you use it in nette framework right? Look at that link
I have sent you and copy the
database: section to your .neon
config and replace dsn with your
also fill out the credentials.
Next step is to inject the connection to your services or presenters https://doc.nette.org/…atabase/core#…
__construct method in example with
class, or inject it as a public property with @inject tag.
Last edited by Rick Strafy (2021-11-18 18:29)
Or if you are using it standalone, just check the source code how
it's parsed from configuration, in your case it's this line https://github.com/…xtension.php#L84
so 4. parameter in the constructor of
Connection class will be
key => value of that config, so
new Connection("dsn", "user", "pwd", [ PDO::SQLSRV_ATTR_ENCODING => PDO::SQLSRV_ENCODING_UTF8 ])