php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56506 General error: 25 bind or column index out of range
Submitted: 2005-08-23 08:03 UTC Modified: 2005-08-24 07:54 UTC
From: tuupola at appelsiini dot net Assigned:
Status: Not a bug Package: PDO_SQLITE (PECL)
PHP Version: 5_1 CVS-2005-08-23 (dev) OS: Solaris 10
Private report: No CVE-ID: None
 [2005-08-23 08:03 UTC] tuupola at appelsiini dot net
Description:
------------
Prepared UPDATE queries seem to die with with error "SQLSTATE[HY000]: General error: 25 bind or column index out of range". Same query called directly via query() works.

Reproduce code:
---------------
http://www.appelsiini.net/~tuupola/php/sqlitebug.phps

the second one is the same code but without the prepared UPDATE query. This one works without error:

http://www.appelsiini.net/~tuupola/php/sqlitebug2.phps

Expected result:
----------------
No errors.

Actual result:
--------------
Exception: SQLSTATE[HY000]: General error: 25 bind or column index out of range

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-23 21:45 UTC] wez@php.net
Please paste working code; I can't reach the links you posted.
 [2005-08-24 03:07 UTC] tuupola at appelsiini dot net
This is the code which generates error:

<?php

try {
    $dbh = new PDO('sqlite:/' . getcwd() . DIRECTORY_SEPARATOR . 'test.db');

    $dbh->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);

    $dbh->query("CREATE TABLE person (
                 id INTEGER PRIMARY KEY NOT NULL,
                 firstname VARCHAR(32),
                 lastname VARCHAR(32),
                 mobile VARCHAR(16))"
                );

    $stmt = $dbh->prepare("INSERT INTO person
                           (firstname, lastname, mobile) 
                           VALUES
                           (:firstname, :lastname, :mobile)"
                         );

    $params['firstname'] = 'A';
    $params['lastname'] =  'A';
    $params['mobile'] =    '1';

    $stmt->execute($params);

    $params['firstname'] = 'B';
    $params['lastname'] =  'B';
    $params['mobile'] =    '2';

    $stmt->execute($params);
 
    $params['firstname'] = 'C';
    $params['lastname'] =  'C';
    $params['mobile'] =    '3';

    $stmt->execute($params);

/*

sqlite> SELECT * FROM person;
1|A|A|1
2|B|B|2
3|C|C|3

*/
    $stmt = $dbh->prepare("UPDATE person 
                           SET firstname=':firstname', 
                               lastname=':lastname', 
                               mobile=':mobile'
                           WHERE (id=2)"
                         );

    $params['firstname'] = 'X';
    $params['lastname'] =  'X';
    $params['mobile'] =    '9';

    $stmt->execute($params);

} catch (PDOException $e) {
    print 'Exception: ' . $e->getMessage() . "\n";
}

?>
 [2005-08-24 03:18 UTC] tuupola at appelsiini dot net
Forgot to mention. PDO and PDO sqlite are 0.9-beta from pecl. PHP itself is few days old snapshot of 5.1. The problem was also verified with PHP 5.0.4 and PDO 0.9 (some linux).
 [2005-08-24 07:54 UTC] wez@php.net
You've made a mistake on your update code.  You should remove the quotation marks from around the :params, otherwise sqlite sees a query with no parameters, and when you supply them, you get that error message.

$stmt = $dbh->prepare("UPDATE person 
                           SET firstname=:firstname, 
                               lastname=:lastname, 
                               mobile=:mobile
                           WHERE (id=2)"
                         );
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 08:01:29 2024 UTC