SQLite Forum

Return boolean if item EXISTS in database
Login
Which query are you running here?

> $EntryExistsBoolean = $db->query("SELECT name FROM myTable WHERE EXISTS (SELECT name FROM myTable WHERE company=SmartCo");

In this version of the query, you are missing the closing parenthesis for your EXISTS clause as well as the string quotes around SmartCo, which would result in SQLite returning that "incomplete input" error message.

Also, `query` returns a result object that you iterate through to fetch each row. https://www.php.net/manual/en/sqlite3.query.php However, in this case, you probably want to use `querySingle` instead. https://www.php.net/manual/en/sqlite3.querysingle.php

Lastly, as others have mentioned, your original query will not work the way you probably intend. So bringing it all together:

```
$EntryExistsBoolean = $db->querySingle("SELECT EXISTS (SELECT 1 FROM myTable WHERE company='SmartCo')");
...
```