本文介绍了PHP PDO Keep获取错误:Charset = UTF8:在dsn字符串中指定了无效的关键字字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直收到此错误:PHP PDO:Charset = UTF8:在dsn字符串中指定了无效的关键字字符集。
I keep getting this error : PHP PDO : Charset=UTF8 : An invalid keyword charset was specified in the dsn string.
我的代码是这样
function ConnectToSQLAndGetDBConnSTRVar() {
try {
$dbname = "irina";
$serverName = ".\SQLEXPRESS";
$username = "USERNAME";
$pw = "PASSWORD";
$dbh = new PDO ("sqlsrv:server=$serverName;Database=$dbname;charset=utf8","$username","$pw");
return $dbh;
}
catch (PDOException $e) {
print "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
}
无论我怎么写utf8 .. UTF8或者UTF-8或者utf-8没有一个为我工作..
那么我该怎么做请帮助我..
And it doesnt matter how I write utf8.. UTF8 or UTF-8 or utf-8 none of them work for me..So what do i do please help me..
推荐答案
您可以在此网址,但它有前缀sybase: ,mssql:或dblib:,具体取决于编译选项。
There is an alternative PDO driver for SQL Server called "PDO_DBLIB", which does take charset as a DSN parameter, but it has the prefix "sybase:", "mssql:", or "dblib:", depending on compilation options.
这篇关于PHP PDO Keep获取错误:Charset = UTF8:在dsn字符串中指定了无效的关键字字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-26 06:45