## Database support

# Wrapper functions

WinBinder also adds a set of database wrapper functions written in PHP.

These functions are simple wrappers around the SQLite and MySQL functions. They are not meant to replace the database functions, but they do simplify the interaction between these functions and the WinBinder controls.

NOTE: Database wrapper functions are available for SQLite and MySQL only.

There are 3 levels of abstraction:

1. Isolate the application from the database in use (here SQLite or MySQL).
2. Isolate the application from the unique table names in the database. In some environments (especially when sharing an existing database with other users) the wrapper prefixes a chosen signature (here called APPPREFIX) to table names to ensure uniqueness.
3. Isolate the application from SQL for table and data manipulation so you can access databases even if you are not familiar with SQL.

The database support functions start with the prefix db_.

For example, to access a record, you just call db_get_data with the table name, id number, and column name. Passing NULL as the id returns an array with the column values for the whole table, while passing NULL as the column returns the record pointed by the id. You may also pass an array of ids and columns and the results will be as expected. This is a very easy and intuitive way of accessing data. Applications that use this database layer and SQLite are completely standalone and don't even require a database server, so installation is a snap to the end user.

The functions that access the database directly reside in the db_mysql.inc.php and db_sqlite.inc.php files. They all have the prefix "raw_db_" as a reminder that you will have to deal with APPPREFIX, id and SQL by yourself. Normally you would only use the "db_" functions.

# SQL support

The original functions and SQL commands are available as well and can be mixed freely with the wrapper library. There are also some wrapper functions (like db_query) that may be used to give direct access to the database using SQL. In this case, the application has to take responsibility for the id field and its attributes as well as any table prefixes.

There are tasks that can nicely be solved with SQL. For example:

- If the application depends on relations between tables that can not programmed conveniently in PHP, then a SQL query will do the job.
- Database administration
- Import and export of tables

# See also

Database functions
db_get_data
db_query