MENU
.net Powerful JavaScript charts

FAQs for the SQLite Editor

Some commonly asked questions about the SQLite Editor

Is this software free to use commercially?

Yes. The SQLite Editor for PHP is released to the public domain - just like SQLite itself is so you can do with it as you wish. Include it in your application, provide it as part of a downloadable or just print the code out and cover your walls with it. Do with it as you wish.

Does this software support any other type of database?

No, but the SQLite-specific parts of the code are minimal, so converting it to or adding support for another type of database won't be difficult.

Is it possible not to delete rows and, instead, mark them as deleted?

Yes, you can do that by changing the default queries. You would change the sql_delete query to update a "deleted" flag on the row instead of performing a delete query and also change the default sql_select option to one that excludes rows that have that deleted flag set (the default for that column should be null).

Can I add one or more buttons to the right of each row?

Yes, you can do this by selecting an empty column in your query and then using the columns_callbacks option to set the HTML for that column. The sql_select option query that selects data for the editor would look like this (the columns_escape option is also set here for this column so the HTML appears instead of the HTML markup itself):

'sql_select'   => "SELECT id,
                          username,
                          created,
                          forename,
                          surname,
                          '' AS `actions`
                     FROM accounts",
'columns_escape' => ['actions' => false],

You could add a columns_names property like this so that the new column does not have a heading. You'd need to use CSS if your headings have a background color but you don't want one for this column.

'columns_names' => [
    'id'       => 'ID',
    'username' => 'Username',
    'created'  => 'Created',
    'forename' => 'Forename',
    'surname'  => 'Surname',
    'actions'  => ''
],

And then in the columns_callbacks option you would need to add the code that creates the button that's added to that empty column.

'columns_callbacks' => [
    'actions' => function ($obj, $row_data, $name, $value)
    {
        return sprintf('<button type="button" onclick="event.preventDefault(); location.href = \'account.php?id=%d\'">View account</button>', $row_data['id']);
        
        // This creates a dropdown list instead of a button. It
        // might be more useful to you if you have a lot of actions.
        // return sprintf('<select onchange="location.href = this.value"><option></option><option value="account.php?id=' . $row_data['id'] . '">View account</option></select>');
    }
],

There's an example in the download archive called examples/accounts.php that demonstrates this technique. Note that if you add a <button> tag, you should give the tag a type attribute with a value of button as shown below. This prevents the delete form being submitted when the button is pressed. For example:

<button type="button" onclick="...">My submit button</button>

Why don't I see any error or confirmation messages from the editor?

The editor can be included in the page at any point, meaning that there's no guarantee that output (ie HTML) may have already started to be sent to the users browser at the point that the editor code runs.

In practice, this means that the editor cannot start a session with the PHP function session_start() because if any output has indeed already been sent then an error will be generated and will show up on the page.

What this means is that you need to start the session yourself using the session_start() function which will allow the editor to successfully show error messages to the user.