It's because `execute()` returns a boolean (as stated in the manual https://www.php.net/manual/en/pdostatement.execute.php ). `fetch()` must be called on `$query`
________________________________________ From: sqlite-users <sqlite-users-boun...@mailinglists.sqlite.org> on behalf of Winfried <codecompl...@free.fr> Sent: 21 October 2019 11:47 To: sqlite-users@mailinglists.sqlite.org Subject: [sqlite] [PHP+PDO] SELECT fails when using prepare + placeholder Hello, I can't figure out why PHP isn't happy with the following query: ============== <?php $dir = 'sqlite:mydb.sqlite'; $dbh = new PDO($dir) or die("cannot open the database"); //INSERT OK $today = date("Y-m-d H:i:s"); $query = $dbh->prepare('INSERT INTO mytable (date, home_id, mode_id) VALUES (?, ?, ?)'); $query->execute(array($today,$home, $mode)); //CREATE TABLE mode (mode_id INTEGER, mode_txt TEXT); //SELECT OK //$query = $dbh->prepare("SELECT mode_txt FROM mode WHERE mode_id=0 LIMIT 1"); //NOK ! $query = $dbh->prepare("SELECT mode_txt FROM mode WHERE mode_id=? LIMIT 1"); $result=$query->execute(array($mode)); if ($result) { //! Fatal error: Call to a member function fetch() on boolean in blah.php $mode = $result->fetch(PDO::FETCH_COLUMN); } $dbh = null; ?> ============== Is it due to some incompatibility between SQLite's INTEGER and PDO? Thank you. -- Sent from: http://sqlite.1065341.n5.nabble.com/ _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users