PHP PDO Keep获取错误:Charset = UTF8:在dsn字符串中指定了无效的关键字字符集 [英] PHP PDO Keep Getting Error: Charset=UTF8 : An invalid keyword charset was specified in the dsn string

查看:1310
本文介绍了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..

推荐答案

You can find the parameters accepted in the DSN string on this page of the PHP manual.

在SQL Server的DSN中没有 Charset 参数PDO驱动程序(带有DSN前缀 sqlserv:)。

There is no Charset parameter in DSNs for the "SQL Server" PDO driver (with the DSN prefix sqlserv:).

请记住,所有PDO驱动程序都有不同的DSN

Bear in mind that all PDO drivers have different DSN conventions, as they are passed directly to the driver and not normalised by PDO.

有一个称为PDO_DBLIB的SQL Server的PDO驱动程序,它的将字符集作为DSN参数,但它有前缀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字符串中指定了无效的关键字字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆