php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68849 bindValue is not using the right data type
Submitted: 2015-01-18 04:41 UTC Modified: -
From: php dot bohwaz at miam dot kd2 dot org Assigned:
Status: Closed Package: SQLite related
PHP Version: 5.4.36 OS: Debian Wheezy
Private report: No CVE-ID:
 [2015-01-18 04:41 UTC] php dot bohwaz at miam dot kd2 dot org
Description:
------------
---
From manual page: http://www.php.net/sqlite3stmt.bindvalue
---

bindValue seems to not be using the right data type for the value. For example most of the time integers are treated as SQLITE3_TEXT instead of SQLITE3_INTEGER. This causes some queries to fail.

Test script:
---------------
<?php

$db = new SQLite3(':memory:');

$db->exec('CREATE TABLE test (a INTEGER);
    INSERT INTO test VALUES (1);
    INSERT INTO test VALUES (2);');

$s = $db->prepare('SELECT COUNT(*) FROM test WHERE (a+1) = ?;');
$s->bindValue(1, 2);
$r = $s->execute();

echo 'Rows returned: ';
echo $r->fetchArray(SQLITE3_NUM)[0];
echo "\n";

$s = $db->prepare('SELECT COUNT(*) FROM test WHERE (a+1) = ?;');
$s->bindValue(1, 2, SQLITE3_INTEGER);
$r = $s->execute();

echo 'Rows returned: ';
echo $r->fetchArray(SQLITE3_NUM)[0];


Expected result:
----------------
Rows returned: 1
Rows returned: 1

Actual result:
--------------
Rows returned: 0
Rows returned: 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-12 17:15 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e49580c96e189b3574a3cbf65d96a7173feb07f0
Log: Fixed bug #68849 bindValue is not using the right data type
 [2016-04-12 17:15 UTC] ab@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:32 UTC] davey@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e49580c96e189b3574a3cbf65d96a7173feb07f0
Log: Fixed bug #68849 bindValue is not using the right data type
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC