Questions And Answers

More Tutorials

PHP Querying a database

//Create a new SQLite3 object from a database file on the server.
 $database = new SQLite3('mysqlitedb.db');
//Query the database with SQL
 $results = $database->query('SELECT bar FROM foo');
//Iterate through all of the results, var_dumping them onto the page
 while ($row = $results->fetchArray()) {

Retrieving only one result

In addition to using LIMIT SQL statements you can also use the SQLite3 function querySingle to retrieve a single row, or the first column.

 $database = new SQLite3('mysqlitedb.db');
//Without the optional second parameter set to true, this query would return just
//the first column of the first row of results and be of the same type as columnName
 $database->querySingle('SELECT column1Name FROM table WHERE column2Name=1');
//With the optional entire_row parameter, this query would return an array of the
//entire first row of query results.
 $database->querySingle('SELECT column1Name, column2Name FROM user WHERE column3Name=1', true);


In this page (written and validated by ) you learned about PHP Querying a database . What's Next? If you are interested in completing PHP tutorial, your next topic will be learning about: PHP Using MongoDB.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.