我目前遇到一个奇怪的错误.
设置:
带有localdb的MSsql Server 2012 Express
目标表归类为:sql_latin1_General_CP1_CI_AS
Zend Server 5.6中的PHP 5.3.9
MCrypt与MCRYPT_RIJNDAEL_256和MCRYPT_MODE_ECB
Sublime Text 2的默认编码(我读的是UTF8 BOM)
我正在使用PDO与MSsql服务器的官方MS适配器.一切都有效:
由于密码,我无法在管理员表中写入一行.
让我们看看我的ENCRYPTED密码:
y"ûƒ^äjw¾bðúl5êù-Ö=W¿Š±¬GP¥Œy÷&ø
这是PDO跟踪:
Array
(
[0] => imsSP
[1] => -7
[2] => An error occurred translating string for input param 3 to UCS-2: No mapping for the Unicode character exists in the target multi-byte code page.
)
sql: [120] INSERT INTO administrator ( [username],[email],[password],[section] ) VALUES(:username,:email,:password,:section)
Params: 4
Key: Name: [9] :username
paramno=0
name=[9] ":username"
is_param=1
param_type=2
Key: Name: [6] :email
paramno=1
name=[6] ":email"
is_param=1
param_type=2
Key: Name: [9] :password
paramno=2
name=[9] ":password"
is_param=1
param_type=2
Key: Name: [8] :section
paramno=3
name=[8] ":section"
is_param=1
param_type=2
当我使用我的MSsql管理中心我可以插入我的行与完全相同的SQL查询.
列设置好,我想:
["id"]=>
string(3) "int"
["username"]=>
string(12) "nvarchar(45)"
["email"]=>
string(12) "nvarchar(45)"
["password"]=>
string(12) "varbinary(45)"
["section"]=>
string(11) "nvarchar(7)"
["country_code"]=>
string(11) "nvarchar(2)"
我使用准备好的语句和bindParam函数,没有额外的选项来执行我的sql语句.
如果有人有一个想法,怎么解决,请让我知道.任何帮助是赞赏!
您应该将排序规则更改为像utf8_unicode_ci这样的几个无人值守的字符.
还应该尝试这样的:
$db = new PDO('foo','bar','blo');
$stmt = $db->prepare("select foo,bar from table where id=?");
$stmt->execute(array($_GET['id']));
$stmt->bindColumn(1,$type,PDO::ParaM_STR,256);
$stmt->bindColumn(2,$lob,PDO::ParaM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
header("Content-Type: $type");
fpassthru($lob);
要检查类型(这是错误/错误开始发生的地方),请执行此检查,甚至可能代替我上面的示例的最后一行:
if (is_string($lob)) echo $lob; else fpassthru($lob);