R
R
rogiivs2019-08-07 15:25:58
PHP
rogiivs, 2019-08-07 15:25:58

Why does PDO SQLite return INT as STRING?

Why does PDO SQLite return INT as STRING , not as INT ? The code and result is below, please tell me where is my mistake.
the code:

<?php
$pdo = new PDO('sqlite:test.db');
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->query(/** @lang sqlite */
    'create table if not exists test (one integer, two integer, three integer)'
);
$insert_prep =  $pdo->prepare(/** @lang sqlite */
    'insert into test values (:one, :two, :three)'
);

$insert_prep->bindValue(':one', 1, PDO::PARAM_INT);
$insert_prep->bindValue(':two',  2, PDO::PARAM_INT);
$insert_prep->bindValue(':three',  3, PDO::PARAM_INT);
$insert_prep->execute();

echo '<pre>';
var_dump($pdo->query(/** @lang sqlite */
    'select * from test'
)->fetchAll(PDO::FETCH_NUM));

execution result:
array(1) {
  [0]=>
  array(3) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "2"
    [2]=>
    string(1) "3"
  }
}

PS I saw the question Why does the pdo driver return an int as a string? and I also read the answers to it, but as you can see, I have the PDO::ATTR_STRINGIFY_FETCHES and PDO::ATTR_EMULATE_PREPARES attributes set to false and still INT is returned as STRING .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leonid, 2019-08-07
@caballero

it has all fields essentially string must be explicitly converted

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question