Show/Hide Toolbars

Navigation: Advanced topics > Programming topics > Data Access Layer (DAL)

PHPrunner32x32     PHPRunner manual


About Data Access Layer

Scroll Prev Next More

 

Data Access Layer (DAL) is now deprecated. While existing code will keep working we recommend to use Database API

Each table in DAL is presented as PHP class, all fields are PHP variables declared in this class.

Variables/Arrays

Variable/Array

Description

Table("TableName")

Provides access to a table.

Example:

global $dal;

$tblCars = $dal->Table("Cars");

Value["FieldName"]

Provides access to the field values. Value["FieldName"] refers to the field to be updated or added.

Example:

global $dal;

$tblCars = $dal->Table("Cars");

$tblCars->Value["Make"]="Volvo";

If the field name contains only English alphabet letters, digits and underscores (doesn't contain spaces and special characters), starts with a letter and doesn't coincide with PHP reserved words, you can also use the following notation to access the field:

global $dal;

$tblCars = $dal->Table("Cars");

$tblCars->Make="Volvo";

Param["FieldName"]

Provides access to the field values. Param["FieldName"] is used in the  WHERE clause of update query. This allows you to avoid the confusion when the same field appears in the field list and in WHERE clause.

Example:

global $dal;

$tblUsers = $dal->Table("UsersTable");

$tblUsers->Param["FirstName"]="Bob";

$tblUsers->Value["FirstName"]="Jim";

$tblUsers->Update();

The corresponding SQL query:

Update UsersTable set 'FirstName'='Jim' where 'FirstName'='Bob'

Methods

Method

Description

Add()

Inserts a new record into the database.

CustomQuery()

Runs custom SQL query.

Delete()

Deletes one or more records from the database.

DBLookup()

Executes an SQL query passed as a parameter and returns the first value of the first entry or null if nothing is found.

FetchByID()

Selects one or more records matching the condition.

Query()

Selects records from database sorting data by orderby field or fields and return recordset.

QueryAll()

Selects all records.

TableName()

Returns table name. This function is used for complex query with calculated fields or joined tables.

Update()

Updates one or more records in the database.

UsersTableName()

Returns properly formatted login table name.

whereAdd()

Adds new AND condition to the existing WHERE clause.

Examples

Before deleting a record check if related records exist

Dynamic SQL Query

Redirect to user info edit page

Show data from master table on details view/edit/add page

Show list of customer orders

Update multiple records on the List page

Update multiple tables

See also

Using DAL functions in projects with multiple database connections