|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 23:00:01 2025 UTC |
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"; } ?>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)" );