note 101827 added to sqlite3.query

From: Date: Thu, 13 Jan 2011 03:31:50 +0000
Subject: note 101827 added to sqlite3.query
Groups: php.notes 
Request: Send a blank email to php-notes+get-175696@lists.php.net to get a copy of this message
The notes for the return value is a little misleading to me. It states that if the query does not "return results" TRUE or FALSE is returned instead. If there is a return value for this method in your PHP code this method always returns an SQLite3Result object, even if you accidentally run an INSERT, UPDATE, DELETE, CREATE TABLE, etc query through it. The only time it returns a TRUE or FALSE is if there is no return value. <?php $result = $dbh->query('CREATE TABLE ...'); if (!($result instanceof Sqlite3Result)) { echo "Query successful."; // This will never echo. } else { $result->fetchArray(); // This will throw an error. } if ($dbh->query('CREATE TABLE ...')) { echo "Query successful."; // Works } else { echo "Query failed."; // Will also work } ?> Use exec() if you are not executing a SELECT query. ---- Server IP: 69.147.83.197 Probable Submitter: 98.114.64.213 ---- Manual Page -- http://www.php.net/manual/en/sqlite3.query.php Edit -- https://master.php.net/note/edit/101827 Del: integrated -- https://master.php.net/note/delete/101827/integrated Del: useless -- https://master.php.net/note/delete/101827/useless Del: bad code -- https://master.php.net/note/delete/101827/bad+code Del: spam -- https://master.php.net/note/delete/101827/spam Del: non-english -- https://master.php.net/note/delete/101827/non-english Del: in docs -- https://master.php.net/note/delete/101827/in+docs Del: other reasons-- https://master.php.net/note/delete/101827 Reject -- https://master.php.net/note/reject/101827 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175696) next »