2

I am trying to connect MSSQL Database Server Using PHP PDO Object Like This:

$dsn='mssql:host=***.***.***.***;dbname=***';      
$username='***';
$passwd='***';

try{

$baglanti=new PDO($dsn,$username,$passwd);
$baglanti->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);    
$baglanti->exec("SET NAMES UTF8");
ini_set('max_execution_time', 2000000);

}catch(PDOException $e){ 

    echo $e->getMessage();
}

I am getting this error after this coding:

SQLSTATE[HY000]: General error: 10007 'NAMES' is not a recognized SET option. [10007] (severity 5)

How can I perform this issue?

Thanks

1 Answer 1

2

MSSQL does not support SET NAMES UTF8

Try using:

$pdo = new PDO('dblib:host=localhost;dbname=databasename;charset=UTF-8', 'username', 'password');

Or

$pdo = new PDO( 
    'mysql:host=hostname;dbname=defaultDbName', 
    'username', 
    'password', 
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") 
); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.