SQLite Forum

Return boolean if item EXISTS in database
Login
The reason why you are having short answers and not a lot of information from us is that this forum is an SQLite forum and your question is really a PHP question.

SQLite does not in any way hold any sway over how the types are interpreted or used in the upstream wrappers for PHP (or indeed any other language).

That said, to put you on the right track, in PHP you are setting $EntryExistsBoolean to a DB Query result (not any variable):

```php
$EntryExistsBoolean = $db->query(...
```

To read anything from that query result (Boolean or otherwise)you need to dereference the data (rows) inside that query result. One way to do this might be:

```php
    $qResult = $db->query("SELECT EXISTS (SELECT 1 FROM myTable WHERE Company_ID = 'SmartCo')");

    $EntryExistsBoolean = False;  // Initialize.

    if ($qResult) { // Ensure the returned result is not null
        // Get a single row as an array from the result
        $row = sqlite_fetch_row($qResult);
        // Check if a row is returned (else the query has no more rows)
        if ($row) {
            // Now translate DB 1/0 to PHP True/False
            $EntryExistsBoolean = ($row[0] <> 0);  
        }
    }

    // And now this all should work as usual
    if (!$EntryExistsBoolean) //FALSE
    {
        echo "Record does not exist"; //Never triggered!
    }
    else  //TRUE
    {
        echo "Item found in the database";
    }
```

Note that I am not familiar with the direct SQLite functions in PHP, nor sure if you use a wrapper or which wrapper you use, the above is simply example code. Your wrapper may well have a built-in way of translating SQL 1/0 to PHP True/False (or even making it all more easy) - the point here is to simply show the two things (SQLite and PHP) are Worlds apart and you cannot assume anything in one system translates directly to the other. (Though good wrappers do make it fit hand-in-glove).

Find the PHP documentation for your API or wrapper, and if it still is unclear, ask some PHP folks, you will have much more helpful responses there I think.