Menu

## Field extends Db
in package

Field.php : 18

ORM Field base class

##### Tags

see
  https://www.kotchasan.com/

### Table of Contents

$table_alias : string
$table_name : string
$cfg : object
  Config class instance.
$conn : string
$db : Driver
  Database connection.
$exists : bool
$primaryKey : string
$request : Request
  Server request class instance.
$table : string
__construct() : mixed
  Class constructor
create() : static
  Create a record
db() : Driver
  Get the database connection.
delete() : bool
  Delete a record
getAllSettings() : object
  Get all database settings.
getConn() : string
  Get the connection name
getFullTableName() : string
  Get the full table name
getPrimarykey() : string
  Get the primary key field name
getSetting() : mixed
  Get the value of a database setting.
getTableName() : string
  Get the table name
getTableWithAlias() : string
  Get the table name with alias
initTableName() : mixed
  Initialize table name and alias
save() : mixed
  Insert or update a record

### Properties

#### $table_alias

Field.php : 23
`public string $table_alias`

The table alias

#### $table_name

Field.php : 28
`public string $table_name`

The table name

#### $cfg

KBase.php : 26

Config class instance.

`protected static object $cfg`

#### $conn

Field.php : 33
`protected string $conn = 'mysql'`

The connection name used to load the config from settings/database.php

#### $db

Db.php : 29

Database connection.

`protected Driver $db`

#### $exists

Field.php : 38
`protected bool $exists`

True if the field is queried, false if it is a new item

#### $primaryKey

Field.php : 43
`protected string $primaryKey = 'id'`

The name of the INT(11) AUTO_INCREMENT primary key field

#### $request

KBase.php : 33

Server request class instance.

`protected static Request $request`

#### $table

Field.php : 48
`protected string $table`

The table name

### Methods

#### __construct()

Field.php : 55

Class constructor

`public __construct([array<string|int, mixed>|object $param = null ]) : mixed`

##### Parameters

$param : array<string|int, mixed>|object = null

  Initial data

##### Return values

mixed —

#### create()

Field.php : 72

Create a record

`public static create() : static`

##### Return values

static —

#### db()

Db.php : 46

Get the database connection.

`public db() : Driver`

##### Return values

Driver —

The database connection.

#### delete()

Field.php : 83

Delete a record

`public delete() : bool`

##### Return values

bool —

True on success, false on failure

#### getAllSettings()

Db.php : 70

Get all database settings.

`public getAllSettings() : object`

##### Return values

object —

The database settings object.

#### getConn()

Field.php : 94

Get the connection name

`public getConn() : string`

##### Return values

string —

The connection name

#### getFullTableName()

Field.php : 105

Get the full table name

`public getFullTableName(string $table) : string`

##### Parameters

$table : string

  The table name specified in settings/database.php

##### Return values

string —

The full table name with prefix, enclosed in backticks (`) if no table name is specified

#### getPrimarykey()

Field.php : 118

Get the primary key field name

`public getPrimarykey() : string`

##### Return values

string —

The primary key field name

#### getSetting()

Db.php : 58

Get the value of a database setting.

`public getSetting(string $key) : mixed`

##### Parameters

$key : string

  The setting key.

##### Return values

mixed —

The value of the setting.

#### getTableName()

Field.php : 128

Get the table name

`public getTableName() : string`

##### Return values

string —

The table name

#### getTableWithAlias()

Field.php : 139

Get the table name with alias

`public getTableWithAlias([string|null $alias = null ]) : string`

##### Parameters

$alias : string|null = null

  The desired alias. If not specified, the defined alias will be used

##### Return values

string —

The table name with the specified alias or the defined alias

#### initTableName()

Field.php : 149

Initialize table name and alias

`public initTableName(Query $db) : mixed`

##### Parameters

$db : Query

  The database query object

##### Return values

mixed —

#### save()

Field.php : 175

Insert or update a record

`public save() : mixed`

##### Return values

mixed —

## Search results