downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SQLite3::querySingle> <SQLite3::prepare
[edit] Last updated: Fri, 25 May 2012

view this page in

SQLite3::query

(PHP 5 >= 5.3.0)

SQLite3::queryFührt eine SQL-Anfrage aus

Beschreibung

public SQLite3Result SQLite3::query ( string $query )

Führt eine SQL-Anfrage aus, welche ein SQLite3Result-Objekt zurück gibt, wenn die Anfrage in einem Ergebnis resultiert.

Parameter-Liste

query

Die auszuführende SQL-Anfrage.

Rückgabewerte

Liefert ein SQLite3Result-Objekt, wenn die Anfrage in einem Ergebnis resultiert. Anderenfalls wird TRUE bei erfolgreicher und FALSE bei erfolgloser Ausführung der Anfrage zurückgegeben.

Beispiele

Beispiel #1 SQLite3::query()-Beispiel

<?php
$db 
= new SQLite3('mysqlitedb.db');

$results $db->query('SELECT bar FROM foo');
while (
$row $results->fetchArray()) {
    
var_dump($row);
}
?>



add a note add a note User Contributed Notes SQLite3::query
pgarvin76 at gmail dot com 12-Jan-2011 07:31
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.

 
show source | credits | sitemap | contact | advertising | mirror sites