note 116412 added to sqlite3.query

From: Date: Mon, 29 Dec 2014 19:55:03 +0000
Subject: note 116412 added to sqlite3.query
Groups: php.notes 
Request: Send a blank email to php-notes+get-201275@lists.php.net to get a copy of this message
Anyone wanting to count the number of rows returned by a query using SQL3 will need to do something like this. <code>$db = new SQLite3("problemswith.sql3"); // the query $results = $db->query( "Select * FROM wordlist WHERE word='$searchword';" ); // the query to count results $count = $db->query( "Select count(*) FROM wordlist WHERE word='$searchword';" )->fetchArray()[0]; // the total number of records $total = $db->query("SELECT count(*) FROM wordlist;")->fetchArray()[0]; echo "Found {$count} results from {$total} records.";</code> It is important to note that your query string should be sanitized if you obtain the data from outside your program like using $_GET and $_POST directly in any SQL query is not only risky but also silly. ---- Server IP: 72.52.91.14 Probable Submitter: 82.132.225.233 ---- Manual Page -- http://php.net/manual/en/sqlite3.query.php Edit -- https://master.php.net/note/edit/116412 Del: integrated -- https://master.php.net/note/delete/116412/integrated Del: useless -- https://master.php.net/note/delete/116412/useless Del: bad code -- https://master.php.net/note/delete/116412/bad+code Del: spam -- https://master.php.net/note/delete/116412/spam Del: non-english -- https://master.php.net/note/delete/116412/non-english Del: in docs -- https://master.php.net/note/delete/116412/in+docs Del: other reasons-- https://master.php.net/note/delete/116412 Reject -- https://master.php.net/note/reject/116412 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201275) next »