Basic Enterprise Application Realm

Basic Enterprise Application Realm Documentation

  • 1 PHP Reference
    • 1.1 Introduction
    • 1.2 shared_lib.php
    • 1.3 ac_tables.php
    • 1.4 ac_email.php
  • 2 Javascript Reference
    • 2.1 Introduction
    • 2.2 ac_ajax
    • 2.3 ac_event
    • 2.4 ac_filter
    • 2.5 ac_menu
    • 2.6 ac_panel
    • 2.7 ac_select
    • 2.8 ac_toc
  • 3 Forms
    • 3.1 Introduction
    • 3.2 How It Works
    • 3.3 AJAX
    • 3.4 form_processor_v2
    • 3.5 form_processor

1.3 ac_tables.php

January 22nd, 2026

Contents

1.3.1 Introduction

ac_tables is not designed to replace a full SQL database such as Oracle or the natively supported MariaDB. However, it is designed to bridge the gap on applications where flat file storage is not appropriate but configuring and managing a full RDBMS seems like a time consuming exercise in over-engineering. As a result it has some (intentional) severe limitations compared to SQL. BEAR itself, makes extensive use of ac_tables to keep track of internal configuration data. The table below outlines the main functional difference between ac_tables and a generic SQL implementation.

ac_tables SQL RDBMS
Table size 1GiB (recommended default) TiB
Max columns unlimited up to 4096 byte file header limit at least 64
Multi user No Yes
User permissions No Yes
Strict input type validation Yes Yes
Preserved output variable types Yes client dependent
Table signing Yes Yes
Binary logging No Yes
Auto defragmentation Yes No
Integrity checking Yes Yes
Numerical indexes Mandatory RDBMS dependant
Indexes id column only Yes
Supports table joins No Yes
SQL No Yes
Built-in functions and constants No Many
Views No Yes
Stored procedures No Yes
Runs as a service No Yes
Supported column types integers (signed), floating points (signed), characters, enumeration, binary blobs integers, characters, varcharacters, enumeration, binary blobs, date, datetime, floating points, JSON, XML, GIS etc.
Full text search No Yes
Table locking Yes (process level) Yes
Row locking No Yes
Transactions No Yes
Result sorting Yes (single column only) Yes (multi-column)
Output limiting No Yes
Sub-queries No Yes
Complex WHERE clauses Yes Yes
Batched UPDATES Yes Yes
Batched REPLACE Yes Yes
Batched INSERT Yes Yes
SHOW TABLES Yes Yes
DESCRIBE Yes Yes
Intelligent error messages Yes Variable
MEMORY / HEAP tables No Yes
Character set UTF-8 Any
Collation None User definable
Storage engine Memory mapped files Various high performance B-Tree data structures

To use ac_tables it must be instantiated as an object in your PHP code. For example:

$table=new ac_tables; $table->use_table('some_table','password');

or

$table=new ac_tables('some_table','some_password');

Table files are stored with the .act extension but are not referenced as such by ac_tables. ac_tables works on logical table names which are mapped to the filesystem so that a simply hierachy of tables can be created. This means that table names are equivalent to file names minus the .act extension.

For example:

Table file: /bear/web_applications/resources/my_app/some_table.act

Table name: /bear/web_applications/resources/my_app/some_table

ac_tables will never confuse a non .act file for a table.

There is no way to recover a password locked table if the password is forgotten. Although the contents of the table are not encrypted so it may be possible to modify the ac_tables class file to ignore password validation.

About matching rules

ac_tables uses a method based API to make calls instead of an actual query language. Many of the most basic SQL equivelants such as INSERT and REPLACE have directly comparable ac_tables methods. However, a major difference is how ac_tables performs matching (the SQL WHERE clause). SQL supports any number of combinations of AND or OR in the WHERE clause. However, ac_tables is limited to using OR only in the context of individual columns. The following are some basic valid SQL statement patterns with indication as to whether ac_tables can achieve the same effective result or not:

Achievable queries

SELECT FROM table WHERE col1 = "value"; SELECT FROM table WHERE col1 = "value1" AND col2 = "value2"; SELECT FROM table WHERE col1 = "value1" OR col1 = "value2"; SELECT FROM table WHERE col1 IN("value1", "value2"); SELECT FROM table WHERE col1 = "value1" AND (col2 = "value2" OR col2 = "value3"); SELECT FROM table WHERE col1 = "value1" AND col2 IN("value2", "value3"); SELECT FROM table WHERE (col1 = "value1" OR col1 = "value2") AND (col2 = "value3" OR col2 = "value4"); SELECT FROM table WHERE col1 IN("value1", "value2") AND col2 IN("value3", "value4");

Non achievable queries

SELECT FROM table WHERE col1 != "value"; SELECT FROM table WHERE col1 = "value1" OR col2 = "value2"; SELECT FROM table WHERE col1 = "value1" OR (col2 = "value2" OR col2 = "value3"); SELECT FROM table WHERE col1 = "value1" OR col2 IN ("value2", "value3"); SELECT FROM table WHERE col1 = "value1" OR (col1 = "value2" AND col2 = "value3"); SELECT FROM table WHERE (col1 = "value1" OR col1 = "value2") OR (col2 = "value3" OR col2 = "value4"); SELECT FROM table WHERE col1 IN("value1", "value2") OR col2 IN("value3", "value4");

1.3.2 Public Properties

Ver. Static Type Default Purpose
rows 1 N integer null Contains the total number of rows in the currently open table.
title 1 N string null The title of the current open table.
writetime 1 N integer null The last update timestamp as the number of seconds since epoch for the currently open table.
signature 1 N string null The signature as a 40 bytes ASCII string for the currently open table.
signedtime 1 N integer null The last table signature update timestamp as tee number of seconds since epoch for the currently open table.
error 1 N string SUCESS The last status message generated by the object. This should reveal an intelligent error message if the status of a method failed.
status 1 N integer 0 The status code for the last method call. Although a call will normally return FALSE if failed, this code can also be used. 0 = success; 1 = failure
last_insert_ids 1 N array null Contains an array of IDs that resulted in the last successful call to ac_tables->insert(), or NULL if insert validation failed.

1.3.3 Methods

Ver. Static Arguments Returns Purpose
__construct 1 N [table (string), password (string)] object reference to ac_tables instance The class constructor. This is implicitly called when the object is created. If no table name is provided, then the ac_tables object will have any table link until you explicitly call the user_table() method.
get_fileinfo 1 N (void) array containing the size and fragmentation percentage of the current table or FALSE if no table is active For the currently active table, this reports on the size in bytes of the file and also the fragmentation as an inverse percentage of used rows versus empty row slots. The keys are as follows: [size] = bytes (integer); [fragmentation] = percentage (integer)
create_table 1 N table (string), title (string), columns (array)[, password (string)] TRUE if the table was created other wise FALSE Create the table identified by table with the free text title provided. The columns are defined by an array structured as follows: [<column_name>] = column definition (string). The column definitions are similar to SQL and follow the pattern <type>(<restriction>). The following types are supported: INT = singed integer restricted by number of digits (up to 10); FLOAT = signed floating point restricted by number of digits (up to 14); ENUM = enumerated values denominated by CSV formatted restriction; CHAR = Text string restricted by the number of bytes; BLOB = Binary string restricted by the number of bytes. The id column is always automatically created. Finally, a password is optional. If provided, then the correct password must be provided to open the table again.
use_table 1 N table (string)[, password (string)] TRUE if successful, otherwise FALSE Used to open and use a specific table. This can be called multiple times on the same ac_tables object to change the currently open table.
drop 1 N table (string) TRUE if successful, otherwise FALSE Deletes the specified table from the filesystem. This should be used with caution since it allows you to delete tables without their password.
show_tables 1 N directory path (string) array of tables found Searches (recursively) the specified directory for .act files and returns an array of found tables. .act files which cannot be opened by ac_tables are not returned. The returned array is multidimensional. each element is a numeric key corresponding to a found table. [n] = table info (array) which contains: [name] = table name (string); [title] = table title (string)
describe 1 N (void) array of column definitions or FALSE is no table is active Provides the description for the current table as an array in the same format used for the column definition argument in the create_table() method: [<column_name>] = column definition (string). The column definitions are similar to SQL and follow the pattern <type>(<restriction>). The following types are supported: INT = singed integer restricted by number of digits (up to 10); FLOAT = signed floating point restricted by number of digits (up to 14); ENUM = enumerated values denominated by CSV formatted restriction; CHAR = Text string restricted by the number of bytes; BLOB = Binary string restricted by the number of bytes. The id column is not part of the descriptive output.
lock 1 N (void) TRUE if successful, otherwise FALSE Acquires a file level lock with the flock() routine on the table preventing other processes from accessing the table until the lock is released.
unlock 1 N (void) TRUE if successful, otherwise FALSE Releases a file level lock with the flock() routine on the table.
sign 1 N (void) (void) Updates the signature on the currently active table.
check 1 N (void) string with the table validation check result Scans the table to check for row consistency against the defined format and the signature. If the signature is not regularly updated with the sign method, then signature errors may be considered normal.
optimise 1 N (void) TRUE if successful, otherwise FALSE Removes the empty rows in the table which results in a smaller size and faster performance by reducing fragmentation to 0%. This requires sufficient disk space for a temporary duplicate of the table being optimised.
insert 1 N VALUES (array) TRUE if successful, otherwise FALSE Inserts one or more rows into the table. If the supplied array is multidimensional, it is assumed to be a batch of rows. Each element in the array corresponds to one column value in the order the columns are defined in. All values in all rows must validate against the expected table structure otherwise the operation is aborted with no inserts. Strict typing is required, therefore a string containing an ASCII integer cannot be passed for a column expecting an integer.
update 1 N WHERE clause (array), SET clause (array) integer containing the number of updated rows Updates specific columns in existing rows that match a pattern defined by the WHERE clause. The WHERE clause is an array or multidimensional array. Each element in the outermost array is considered part of an AND clause. If a value in the outermost array is also an array, it is considered to be an OR clause for the same column. For example: [col1] = "val1", [col2] = array("val2", "val3") is equivalent to SQL like: ... WHERE col1 = "val1" AND col2 IN("val2", "val3"). The SET clause is a simple array where keys correspond to column names and contain the values to be used in the update. For example: [col1] = "newval1", [col3] = "newval2"
update_id 1 N IDs (mixed), SET clause (array) integer containing the number of updated rows Updates specific columns in existing rows that match the IDs supplied. The ID can be a single ID as an integer or an array of IDs for multiple row updates with the same SET clause values. The SET clause is a simple array where keys correspond to column names and contain the values to be used in the update. For example: [col1] = "newval1", [col3] = "newval2".
replace 1 N IDs (mixed), VALUES (array) integer containing the number of updated rows Updates existing rows that match the IDs supplied. The ID can be a single ID as an integer or an array of IDs for multiple row updates. Each element in the array corresponds to one column value in the order the columns are defined in. All values in all rows must validate against the expected table structure otherwise the operation is aborted with no inserts. Strict typing is required, therefore a string containing an ASCII integer cannot be passed for a column expecting an integer. If VALUES is a multidimensional array, it should have the same number of entries as IDs. If there are multiple IDs but only one row of values in VALUES, then all matching rows are replaced with the same values.
delete 1 N WHERE (array) integer containing the number of updated rows Deletes rows that match a pattern defined by the WHERE clause. The WHERE clause is an array or multidimensional array. Each element in the outermost array is considered part of an AND clause. If a value in the outermost array is also an array, it is considered to be an OR clause for the same column. For example: [col1] = "val1", [col2] = array("val2", "val3") is equivalent to SQL like: ... WHERE col1 = "val1" AND col2 IN("val2", "val3")
delete_id 1 N IDs (mixed) integer containing the number of updated rows Deletes rows that match the IDs supplied. The ID can be a single ID as an integer or an array of IDs for multiple row deletes.
select 1 N WHERE (array)[, column list (array)] array of found rows Retrieves rows that match the WHERE clause. The WHERE clause is an array or multidimensional array. Each element in the outermost array is considered part of an AND clause. If a value in the outermost array is also an array, it is considered to be an OR clause for the same column. For example: [col1] = "val1", [col2] = array("val2", "val3") is equivalent to SQL like: ... WHERE col1 = "val1" AND col2 IN("val2", "val3") . If the optional column list is supplied, only the specified columns are returned. It is a simple indexed array with values corresponding to column names in the table. If not supplied, all columns are returned. The id column must not be specified as it is mandatory and always returned for each row.
select_id 1 N IDs (mixed)[, column list (array)] array of found rows Retrieves rows that match the IDs supplied. The ID can be a single ID as an integer or an array of IDs for multiple row selects. If the optional column list is supplied, only the specified columns are returned. It is a simple indexed array with values corresponding to column names in the table. If not supplied, all columns are returned.
count 1 N WHERE (array) integer of matching rows Counts all the rows that batch the condition in the WHERE clause. The WHERE clause is an array or multidimensional array. Each element in the outermost array is considered part of an AND clause. If a value in the outermost array is also an array, it is considered to be an OR clause for the same column. For example: [col1] = "val1", [col2] = array("val2", "val3") is equivalent to SQL like: ... WHERE col1 = "val1" AND col2 IN("val2", "val3")
reorder 1 N result set (array-ref), column name (string)[, order (enumeration)] TRUE on success, otherwise FALSE This method will reorder any multidimensional array (not just ac_tables result sets) according to the key supplied as the column name argument in the order specified. Valid order values are: ASC = sort ascending; DESC = sort descending. It acts on the original array.
previous: shared_lib.php next: ac_email.php