|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-08-15 15:38 UTC] face at dfhu dot org
[2009-08-15 16:36 UTC] scottmac@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 14:00:01 2025 UTC |
Description: ------------ PDO::Execute quotes integers even though this will cause problems in SQLite. SQLite has type affinity and sometimes requires hard checks. that is "(product_id) VALUES ('1')" is NOT the same as "(product_id) VALUES (1)"; Thanks! -- Victory http://dfhu.org/blog/ Reproduce code: --------------- $pdo=new PDO("sqlite:./db/sales.sqlite"); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql=" CREATE TABLE IF NOT EXISTS sales ( product_id INT CHECK(typeof(product_id) = 'integer') )"; $pdo->query($sql); $sql=" INSERT INTO sales (product_id) VALUES (:product_id)"; $statement=$pdo->prepare($sql); // this will throw a integrity constraint error $statement->execute(Array(":product_id"=>1)); Expected result: ---------------- I do not expect to see an exception thrown, i expect PDO::execute() to not quote integers in SQLite. Thus there should be no output. Actual result: -------------- Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 19 constraint failed'