note 125331 added to ref.pdo-sqlite

From: Date: Fri, 04 Sep 2020 15:19:57 +0000
Subject: note 125331 added to ref.pdo-sqlite
Groups: php.notes 
Request: Send a blank email to php-notes+get-215075@lists.php.net to get a copy of this message
With PDO SQLite driver, calculation within an SQL with multiple ? may not get results as you expect. <?php // .... $stmt = $PDO->prepare('SELECT * FROM X WHERE TimeUpdated+?>?'); $stmt->execute([3600, time()]); $data = $stmt->fetchAll(); print_r($data); ?> To get the right results, you have more than 3 solutions. 1. Change 'SELECT * FROM X WHERE TimeUpdated+?>?' to 'SELECT * FROM X WHERE TimeUpdated>?' and do the math using Php (ie: $stmt->execute([time()-3600]); ). 2. Use PdoStatement::bindParam or PdoStatement::bindValue, and set the parameter type to PDO::PARAM_INT. 3. Change 'SELECT * FROM X WHERE TimeUpdated+?>?' to 'SELECT * FROM X WHERE TimeUpdated+?>?+0', here '?+0' may be replaced by another math function or another calculation, such as 'abs(?)', you can even wrap both ? with a math calculation. ---- Server IP: 45.112.84.4 Probable Submitter: 103.51.167.36 (proxied: 175.154.85.69) ---- Manual Page -- http://php.net/manual/en/ref.pdo-sqlite.php Edit -- https://master.php.net/note/edit/125331 Del: integrated -- https://master.php.net/note/delete/125331/integrated Del: useless -- https://master.php.net/note/delete/125331/useless Del: bad code -- https://master.php.net/note/delete/125331/bad+code Del: spam -- https://master.php.net/note/delete/125331/spam Del: non-english -- https://master.php.net/note/delete/125331/non-english Del: in docs -- https://master.php.net/note/delete/125331/in+docs Del: other reasons-- https://master.php.net/note/delete/125331 Reject -- https://master.php.net/note/reject/125331 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#215075) next »