Database examples, including DBTNG.
'DBTNG' means 'Database: The Next Generation.' Yes, Backdroplers are nerds.
General documentation is available at database abstraction layer documentation and at Database API.
The several examples here demonstrate basic database usage.
In Backdrop the usage of db_query() for INSERT, UPDATE, or DELETE is deprecated, because it is database-dependent. Instead specific functions are provided to perform these operations: db_insert(), db_update(), and db_delete() do the job now. (Note that backdrop_write_record() is also deprecated.)
db_insert() example:
// INSERT INTO {dbtng_example} (name, surname) VALUES('John, 'Doe')
db_insert('dbtng_example')
->fields(array('name' => 'John', 'surname' => 'Doe'))
->execute();
db_update() example:
// UPDATE {dbtng_example} SET name = 'Jane' WHERE name = 'John'
db_update('dbtng_example')
->fields(array('name' => 'Jane'))
->condition('name', 'John')
->execute();
db_delete() example:
// DELETE FROM {dbtng_example} WHERE name = 'Jane'
db_delete('dbtng_example')
->condition('name', 'Jane')
->execute();
See Database Abstraction Layer
See also
Parent topics
File
- modules/
examples/ dbtng_example/ dbtng_example.module, line 14 - This is an example outlining how a module can make use of the DBTNG database API in Backdrop.
Functions
Name![]() |
Location | Description |
---|---|---|
dbtng_example_schema |
modules/ |
Implements hook_schema(). |
dbtng_example_menu |
modules/ |
Implements hook_menu(). |
dbtng_example_list |
modules/ |
Render a list of entries in the database. |
dbtng_example_install |
modules/ |
Implements hook_install(). |
dbtng_example_form_update_submit |
modules/ |
Submit handler for 'update entry' form. |
dbtng_example_form_update_callback |
modules/ |
AJAX callback handler for the pid select. |
dbtng_example_form_update |
modules/ |
Sample UI to update a record. |
dbtng_example_form_add_submit |
modules/ |
Submit handler for 'add entry' form. |
dbtng_example_form_add |
modules/ |
Prepare a simple form to add an entry, with all the interesting fields. |
dbtng_example_entry_update |
modules/ |
Update an entry in the database. |
dbtng_example_entry_load |
modules/ |
Read from the database using a filter array. |
dbtng_example_entry_insert |
modules/ |
Save an entry in the database. |
dbtng_example_entry_delete |
modules/ |
Delete an entry from the database. |
dbtng_example_advanced_list |
modules/ |
Render a filtered list of entries in the database. |
Classes
Name![]() |
Location | Description |
---|---|---|
DBTNGExampleUnitTestCase |
modules/ |
Default test case for the dbtng_example module. |