[英]PDO_SQLSRV returns all results as strings
For SQL Server integer data types it seems PDO_SQLSRV returns strings whereas SQLSRV returns integers. 对于SQL Server整数数据类型,似乎PDO_SQLSRV返回字符串,而SQLSRV返回整数。 My already written app does explicit checking (===) in several places so that means PDO_SQLSRV not a drop in replacement for SQLSRV.
我已经编写的应用程序在多个位置进行了显式检查(===),这意味着PDO_SQLSRV不会取代SQLSRV。 Normally I wouldn't be considering PDO - however Doctrine seems to use PDO and I couldn't find a Microsoft SQLSRV driver for it (enlighten me, please!)
通常,我不会考虑使用PDO-但是Doctrine似乎在使用PDO,而我找不到用于它的Microsoft SQLSRV驱动程序(请启发我!)
Here is the sample code with the responses: 这是带有响应的示例代码:
PDO PDO
$sql = "SELECT Top 1 * FROM Users";
$stmt = $conn->query($sql);
$things = $stmt->fetchAll(PDO::FETCH_ASSOC);
var_dump($things);
Data: 数据:
'ID' => string '344' (length=3)
'UserName' => string 'admin ' (length=30)
SQLSRV SQLSRV
$sql = "SELECT Top 1 * FROM Users";
$things = sqlsrv_query($conn, $sql);
$thingsArray = [];
while( $row = sqlsrv_fetch_array($things, SQLSRV_FETCH_ASSOC))
{
$thingsArray[] = $row;
}
var_dump($thingsArray);
Data: 数据:
'ID' => int 344
'UserName' => string 'admin ' (length=30)
So - right now I think I have two choices: carefully release this and make sure that I'm typecasting integers or loosening my comparisons, or write/find a Doctrine SQLSRV library. 所以-现在,我认为我有两个选择:小心释放它,并确保我正在强制转换整数或放松我的比较,或者编写/查找Doctrine SQLSRV库。
Does anyone know of a setting for PDO_SQLSRV that will return integers as integers? 有谁知道PDO_SQLSRV的设置将整数返回为整数吗? I've checked the docs, but can't seem to find anything.
我检查了文档,但似乎找不到任何东西。
Also SQLSRV returns dates as native PHP DateTime objects. SQLSRV还将日期作为本机PHP DateTime对象返回。 Kinda cool, but not important.
有点酷,但并不重要。
PHP PDO规范指出所有字段都以字符串形式返回,因此pdo_sqlsrv只是遵循该规范。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.