Beginner's Guide to DaDaBik - a Tutorial

alpha2zee

Well-known member
A Beginner's Guide to DaDaBik

This is a very basic, beginner's tutorial written for DaDaBik version 3.2 and 4.0-alpha, although most points will apply for other versions as well. It should be considered perpetually 'under construction' for error-correction, additions, etc.

Contents

1. What is DaDaBik
2. Requirements
3. History
4. Should you use DaDaBik?
5. Other DaDaBik-like software
6. Glossary
7. How DaDaBik works
8. Creating MySQL tables before installing DaDaBik
9. Installing DaDaBik
10. Authentication / security
11. Configuring forms
12. Adding, editing or removing tables
13. The appearance or style of DaDaBik-generated web-pages
14. Customizing/modifying DaDaBik application logic
15. Backups
16. More help

1. What is DaDaBik

The DaDaBik 'database interface creator' is a PHP application* that provides a web-based interface to data in a database to modify (by adding, deleting or editing) or explore (by browsing or searching). Two most useful features of DaDaBik are -

1) It's operability is independent of the type of data in the database or its organizational scheme. That is DaDaBik can be used to manage a business's invoices as well as a personal collection of music CDs. Thus also, it can be used to manage multiple tables.
2) It can be configured to alter the interface used to interact with data. Most web-based interactions with data take place through forms that are coded in the HTML language. DaDaBik allows one to dictate the form parameters when handling data. For example, when new data is being added, to dictate that a certain form field be a required one.

DaDaBik has features such as data export, field-specific (and combinatorial) searches, multi-lingual (European languages) support, form field validation, user account system, duplication check, form configuration, etc.

The content generated by DaDaBik is in the HTML 4.0 specification and is CSS-compliant. However, it is not UTF-8 (Unicode)-encoded.

*PHP applications are made of PHP scripts (.php files) that are interpreted ('acted upon') by webservers to interact with databases, generate HTML-encoded webpage files, etc. For this to work, webservers need to be PHP-enabled. For the commonly used, free Apache webserver, for example, this involves the installation of the PHP module and its activation by editing the httpd.conf configuration file.

2. Requirements

1) A webserver with PHP (versions 4.05 and up) enabled. The magic_quotes_gpc* parameter should be enabled ('on'; usually disabled in later versions of PHP) in the PHP configuration file (php.ini) or through a .htaccess file in the DaDaBik directory (by adding this line: php_flag magic_quotes_gpc on).

If you wish to use the file-upload feature, file upload feature of PHP should also be enabled (usually enabled by default). Furthermore, file permissions should be correctly set for both the 'temp' directory used by PHP and the 'uploads' sub-directory inside DaDaBik. Also note that a server's PHP settings usually have a maximum file-upload size setting and a timeout setting.

*There are code modifications that allow one to use DaDaBik irrespective of the magic_quotes_gpc setting. See this post for example.

2) The database should be in MySQL* (version 3.23.x and above) in case of DaDaBik version 3.2. Support for other database-types has been enabled in version 4.0 through the ADOdb database abstraction library although only PostgreSQL (version 8) has been well-tested (as of November 2005).

3) A 'modern' (standard-compliant) Javascript-enabled browser - Safari, Firefox, Netscape 7 and up, Internet Explorer 5 and up, etc., should all work well, though there could be browser-specific issues.

*There could be some issues if MySQL is running in the strict mode. Also note that interaction with large databases can be affected by MySQL server timeout settings.

3. History

(As of November 2005)

Nov 2001 - Eugenio Tacchini releases first version of DaDaBik
Jun 2002 - Version 2 released; supports multiple tables
Oct 2002 - Version 2.2 incorporates file uploading
Mar 2004 - Version 3 allows data export (in CSV format) and has many extra features. However, it disables multiple-menus.
Jul 2004 - Version 3.1 introduces authentication (user account system)
Jun 2005 - Version 4.0 alpha released; supports various database types
Oct 2005 - DaDaBik development moves to a Subversion (SVN)-based system (at GNA.org)

4. Should you use DaDaBik?

DaDaBik is very useful if you are using multiple tables (each storing data of a different type), or a single table and you do not want to hand-code.

DaDaBik largely displays the data fetched from the database as such. It does do some simple manipulations (such as displaying information tagged as 'URL' as a link or an 'image' as an image), but it does not do more (such as displaying the number of days since information tagged as 'date'). Some of this limitation arises because DaDaBik is designed for use irrespective of the data type. Your requirements may thus not be fulfilled by DaDaBik, though simple modifications can satisfy your needs (see this example modification) and you can use DaDaBik and avail of its useful features.

Otherwise you may want to consider using DaDaBik as a 'backend,' especially if you handle many database tables. See this thread for example scripts that use DaDaBik as a backend.

It should be kept in mind that data that is rarely altered and/or 'ungroupable' (pieces of data that cannot be grouped based on their characteristics) and/or 'simple' (akin to a table with just one or two columns) need not be stored in a database at all. Plain webpage files are perhaps simple.

5. DaDaBik-like software

phpMyAdmin is perhaps the software that comes closest to DaDaBik. However, it is meant for use by tech-savvy users and has features, though exceptionally good, that are meant for database administration rather than database browsing or a/e-mending.

6. Glossary of terms

Configuration - administering the form interface (number of fields, type of fields, etc.) presented during data insertion or editing
Content type - type of data stored in a field of a database table; used by DaDaBik, for example, validate a form, rejecting the submission if alphabetical text is entered in a field meant for numerical information.
Database - contains one or more tables
Duplicate - when inserting a new record, a 'duplicate' warning may be issued if an older record has similar content
Field - a column; a part of a row; a key; also, a part of a form
Field type - type of the field of a form (in the HTML context); such as plain text (text), a textbox (textarea), pull-down menu, etc.
Form - an element of a web-page used to submit information to interact with the database
Label - text used to label a field of a form; in DaDaBik, generally the description of a database table field
Option - a choice presented in a form field in the form of a pull-down/selection menu (or checkboxes or radioboxes)
Primary key - each table should have a field set as a primary key; no two rows (records) should have the same value in the primary key field
Record - a row of a table (an 'entry')
Table - can refer to a table in a database (such as a MySQL table) or to a table in a web-page that is in HTML (an HTML table)
Table, details - the HTML table showing detailed information for a record
Table, foreign - refers to a database (not HTML) table other than the primary table that is being affected; can be used to fetch information to generate form menu options
Table, installing - refers to 'adding' an existing MySQL database table to DaDaBik; DaDaBik generates an internal table and adds the installed table's name to a 'table of tables' that was created in the database by DaDaBik when it was installed
Table, internal - a table in the database that is generated by DaDaBik; for every managed table, DaDaBik adds an internal table that are named similarly but with a preifx (such as dadabik_) to hold configuration information
Table, refreshing - if the database table is altered by addition of new fields, the table needs to be 'refreshed.' This basically adds the new field into the corresponding internal table.
Table, results - the HTML table displaying listing of records (all, or some if searching)
Table, users - DaDaBik can be set to use an authentication system based on user accounts. The 'users table' is used to hold the account information. You may already have such a table in your database. DaDaBik itself installs a user table (users_tab). This table is defined in DaDaBik's configuration file (config.php).

7. How DaDaBik works

Though DaDaBik can be used to manage multiple tables, at any instance (of browsing), DaDaBik 'works' with a single table in the database. That table's name is used to fetch all or some (when searching) of its rows (records) to display as a list ('results table') for browsing. The records can then be individually accessed for editing or deleting or for getting more details.

For every table, there is a corresponding form that is generated during insertion of a new record or the editing of an existing record or searching. For every field of the database table, there is, theoretically, a corresponding field in the HTML form. The parameters associated with the form field include those used to describe the form field ('label'; like, 'Full name' for a table field named 'name'), its validation ('Is the field a required one?'), its type (pull-down menu), etc. All this information is set by configuring the form and is stored in an internal table.

8. Creating MySQL database tables before installing DaDaBik

DaDaBik does not install the primary tables of the database. You have to do it yourself. Similarly, DaDaBik requires that the database is served through a database server (like MySQL) and that the right connection settings are described in the DaDaBik configuration file (config.php inside DaDaBik directory).

Once you have an account to use the database server (the account need not have all privileges but the privilege to delete and create tables is a must), set up a database first and then create the tables to fill the database. Of course, you should 'design' the tables well, depending on your needs, usability, etc.

There are stand-alone applications like Navicat and MySQL's free Query Browser as well as web-based ones like phpMyAdmin that can be used to create the database and its tables if you are not familiar with command-line MySQL (and, usually, even if you are).

1) Keep all table and field names short (but 'understandable' by you); do not use unusual characters - stick to just 0-9 and a-z in small case, and hyphen (-) but not space. Different tables can share some of the field names.
2) In MySQL, it is usually good to declare each field to be 'NOT NULL'
3) Depending on the data you intend for a field, set its TYPE and LENGTH properly (for efficiency, speed, etc.). For example, for a field to store telephone numbers, the VARCHAR type of LENGTH 16 characters is better than 255 characters.
4) Designate a field as PRIMARY. This field will have unique values for each record. It is best to create a field named id, db_id, etc., of type INT (integer) and make it the primary key. Since the values have to be exclusive, set it for AUTO-INCREMENT. That way, a value for this field for a new record need not be declared - it will automatically be the next number.
5) If you declare a certain field as primary key, that field cannot contain more than a certain number of characters (usually a few hundreds)
6) If you designate a field 'NOT NULL' and if the MySQL server is in strict mode, you may have to declare a DEFAULT value for the field if it is not set for AUTO-INCREMENT
7) If you want to use a field for storing dates on which a record was created/edited (by setting the form field type to insert_ or update_date in the DaDaBik form configurator), you need to set its type to DATE
8) If you want to use the user-based restriction-to-records features (more in section 10 below), you should have a field named ID_user (VARCHAR (64), NOT NULL).
9) Note that DaDaBik can be used to manage more than one table.

9. Installing DaDaBik

1) Download DaDaBik from this site (or the latest, though still under development, from GNA.org).
2) Uncompress the folder
3) Edit config.php to set database connection settings, etc. Note to be careful of typographical mistakes (missing slashes, etc.). Also note that if the database server is on the same host (same computer) as the web-server, you may use ':/path/to/socket' (most likely '/tmp/mysql.sock' for MySQL) instead of 'localhost' for speed. The database server account being used should have table creation/deletion privileges.
4) Move the DaDaBik directory to the web server folder; check the file-permissions for the uploads directory if you plan to use file uploads.
5) Browse to domain.com/path/to/DaDaBik/index.php and follow directions. (You should have the database tables setup a priori.)
6) You may wish to set up .htaccess file-based restrictions or PHP parameters.

10. Authentication and security

DaDaBik comes with an authentication system that can be enabled to varying extent. It is turned OFF by default (partameters are in config.php file). You may want to leave it so. Even then you should consider securing the administrative pages (admin.php, internal_table_manager.php and install.php) through through .htaccess files, etc.

If you enable authentication, one will need to log in to even view the records. Some may consider this a drawback. Also, login checks are session-based, meaning one will have to log in every time they restart their web browser*.

DaDaBik uses the 'users_tab' table it installs during installation as the default users table (a database table holding information on user accounts such as usernames and encrypted [MD5 algorithm] passwords). You can use a different table by changing parameters in config.php. The 'users_tab' has one pre-installed entry - for an adminitrative account with username - root - and password - letizia.

If you enable user-based restrictions to records**, the creator (owner) of the record, and not even an administrative account-holder, may view details / search for and find / edit / delete it. Again, such parameters are set in the config.php file. For this to work, you must have a field named ID_user in the database table(s) (not the internall tables - see glossary above) and you must set it to type ID_user in the form configurator (see below) and disable display its display results table and insert/update forms.

The administrative users can add or edit user accounts. Note that the password field has to be filled with MD5-encrypted password. You can use the 'create password' link shown when working with the users table to do so. However, any user can access the administrative pages.

See this thread for more.

Extra authentication through .htaccess files can also be added.

*A modification for cookie-based auto-login ('remember me') is described in this post.

** A drawback of this is that there may be problems if the user system was not enabled to this extent previously or if a user 'leaves.' A solution to this (user re-assignment) is described in this post.

11. Configuring forms

As mentioned earlier, every table has an associated form, with every table field represented by a form field. Form configuration involves configuring the presentation of such fields in the details table, the results table, the search form, the editing form, etc.

Parameters that can be configured include those that deal with -

1) showing or not showing a field
2) the HTML nature of the field (a textbox, a pull-down (selection) menu, width of a text field, etc.)
3) requirement for the field to be filled ('required field')
4) using value in the field for alerting about possible duplicate records being created
5) assigning a default value to prefill the form field
6) and more...

See DaDaBik's documentation for more. Some aspects are however detailed below.

Foreign tables

For form fields that are selection menus, the options provided in such menus can be specified manually in the form configurator ('Option to include') or they can be dynamically dictated using field values from a separate database table (foreign table). These parameters in the form configurator have to be set for such a form field - 'Primary key field' - the primary key (field name) of the foreign table; 'Primary key table' - the name of the table; 'Linked fields' - the names of the field(s) whose values will be shown as options. Atleast one field name should be added to 'Linked fields'.

Suppose you have a table 'albums' that contains information about CDs and has this scheme (these fields) - id (primary key; a number), title (the album title), artist (full name of artist) and genre (genre). Now in the form that deals with this table, you may want to use a pull-down (select) menu to show names of artists (options) of whom one has to be chosen, and the names of artists come from a different table 'artists,' with scheme - id (primary key), first_name (first name), and last_name (last name). Thus, for the form field for 'artist' (for the 'albums' table), you would use 'id' for 'Primary key field,' 'artists' for 'Primary key table,' and 'first_name~last_name' for 'Linked fields.'

A modification that provides added functionality (restricting the field values, etc., by passing extra MySQL SELECT clauses; say, only artists whose last names begin with a D in the example above) to this feature is described in this post.

File uploads

If a field type is set as a generic_file (or image_file), one is provided with an option to upload a file. File size and extension-based type restrictions can be set in config.php. If the field type is image_file, the image itself will be displayed in the results and details table. Otherwise, the name of the file linked to the file itself is displayed. Uploaded files are stored in the folder 'uploads' in DaDaBik. The database tables themselves do not hold the files but justthe file names.

Modifications addressing certain issues with the 'file' field-type in DaDaBik 3.2 and 4.0-alpha have been posted - for example, this and this.

Multiple selection

The pull-down menus can only be of single_select type. Multiple selection of options through multiple_select menus or checkboxes may be enabled through this modification.

12. Adding, editing or removing tables

As mentioned earlier, every table 'managed' by DaDaBik has a corresponding internal table each of whose rows represent each of the table's fields.

Thus, if a field name is altered, or if a new field is added (or an existing one deleted), then that needs to be reflected in the internal table's content.

One uses options provided in the administration page (admin.php) to get things done so.

13. The appearance or style of DaDaBik-generated web-pages

For style changes (font ypes, colors, etc.), edit the CSS stylesheet files in the css sub-directory inside DaDaBik.

If your results table (the record lists) appears too wide, consider making some fields 'not to be displayed' in the results table. One can always see them by clicking for more details to get to the details table. Also consider changing these parameters in config.php - $word_wrap_col, $word_wrap_fix_width and $enable_word_wrap_cut.

A modification to incorporate field-specific styles (column width, background-color, etc.) has been described in this post.

14. Customizing/modifying DaDaBik application logic

Code modifications that may suit your needs may have been posted in these forums or on Sourceforge.net.

If you have a successful modification to the code resulting in a useful functionality or fixing of a bug, please consider posting in the forums.

If you do wide-spread modifications to the code, consider posting downloadable files on Sourceforge.net too (e.g., this posting).

DaDaBik development may be followed on the Subversion control management system at GNA.org.

Below is a brief on the DaDaBik code files.

PHP files primarily for web-page display

1) index.php - for results and details tables and for search and insert/edit forms
2) admin.php - for table installations, refreshing, etc.
3) internal_table_manager.php - for form configuration
4) login.php - for log in
5) header.php and footer.php (and corresponding _admin_ files) - for generating content for the top (header) or bottom (footer) of the web-pages

Some of the other PHP files

1) include/config.php - has configurable parameters
2) include/adodb - the database abstraction library; best left untouched
3) include/business_logic.php - the main 'brain' with most of the complex functions
4) include/general_functions.php - includes some form-field validation functions
5) admin.php - functions for table installations, refreshing, etc.

Some important functions

1) include/business_logic.php/build_form - generates form for inserting a record or editing it and for searches

2) include/business_logic.php/check_required_fields - for checking that a required field is filled

3) include/business_logic.php/check_fields_types - for validating a field value (for example, if numerical data is entered, etc.)

4) include/business_logic.php/build_select_duplicated_query - to look for possible duplication during record insertion

5) include/business_logic.php/build_insert_duplication_form - when deciding to 'insert anyway' after a 'possible duplication' warning.

6) include/business_logic.php/insert_record - for inserting submitted form values into database

7) include/business_logic.php/update_record - for updating database with submitted form values

8) include/business_logic.php/get_field_correct_displaying - for properly displaying a field value (e.g., an image_file type as an image) in the results and details tables

9) include/business_logic.php/build_results_table - shows listings of records as the results table

10) include/business_logic.php/build_details_table - shows record details as the details table

11) include/business_logic.php/create_internal_table - create internal table

12) admin.php/uninstall_table, refresh_table, etc. - as suggested by the names

15. Backups

The main items to keep regularly backed-up copies of are the database and the uploads folder which contain any uploaded files. This can be done manually by copying of the 'uploads' directory and mysqldumps (in case of a MySQL database).

There are applications like Navicat that can be set to automatically and periodically backup your database. Alternately, you can set up timed scripts using programs such as cron and launchd.

16. More help

To get more help, read DaDaBik's documentation and FAQ and search these forums. Try a different though similar term if you do not get any results.

If your issue has not been resolved in some posting, do post. Please also add the DaDaBik version as well as version numbers of PHP, MySQL, web-server, operating system, browser, etc., to your post.

Often issues arise not because of a problem in the DaDaBik code but because of more general database/operating system/PHP-specific problems. Consider searching the web for solutions posted elsewhere by others.

Turning on the debug options in config.php will display any error messages in detail and posting such messages may clarify the issue to those who want to help.



Post Edited (12-08-05 11:31)
 
Top