Php Pdo Sqlsrv Always Return Every Values As String
How do I get value from DB with correct field type? I'm using PDO Sqlsrv to fetch data from DB and I always receive data as string like: customer_id : '1' My customer_id field type
Solution 1:
Answer :
I will answer exactly to your question and what you may try is to use PDOStatement::bindColumn. You use PHP 5.5 and based on support matrix, your PHP Driver version should be 3.1 or 3.2. In this version, based on change log, SQLSRV_ATTR_FETCHES_NUMERIC_TYPE is not supported.
...
$stmt->bindColumn('customer_id', $customer_id, PDO::PARAM_INT);
$stmt->bindColumn('phone_number', $phone_number, PDO::PARAM_STR);
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
var_dump($customer_id);
var_dump($phone_number);
echo'<br>';
}
...
Solution 2:
You don't say what version of SQLSRV you are using but chances are that it's older than 4.0.8, when the directive was implemented:
[Added]
- SQLSRV_ATTR_FETCHES_NUMERIC_TYPE attribute support.
I don't think there's a simple generic way to determine what your version is (phpinfo()'s output does not display it) but you can just upgrade to latest version.
Update: try sqlsrv_client_info().
Post a Comment for "Php Pdo Sqlsrv Always Return Every Values As String"