---
title: "SQL.Connection"
description: "Abstract SQL connection prototype."
canonical_url: "https://www.zeyos.com/zymba/ref/sql/sql-connection"
markdown_url: "https://www.zeyos.com/ai/guide/zymba/ref/sql/sql-connection.md"
section: "zymba-reference"
authority: "reference"
language: "en"
source_repository: "https://cloud.zeyos.com/__doc/zymbaref.json"
source_sha256: "05a361c6ddc32e74f4a6dc16fd06f218210ff1b7ce57f26ca1994bfffc407915"
---

# SQL.Connection

## SQL.Connection

```
object @SQL.Connection(@Base) {
	begin(): $this {}
	close() {}
	commit(): $this {}
	countAffectedRows(): int {}
	countRowsInTable(string $table): int {}
	delete(string $table, object $conditions): int {}
	exists(string $table, object $conditions): bool {}
	exit() {}
	fetchAll(string $query, bool $indexed): object {}
	fetchAllOfField(string $query, int $index): object {}
	fetchOne(string $query, bool $indexed): object {}
	getCharset(): string {}
	getDatabaseName(): string {}
	getDatabaseSize(): int {}
	getLastInsertID(): int {}
	getVersion(): string {}
	insert(string $table, object $data): int {}
	listFieldsInTable(string $table): object {}
	listTables(): object {}
	query(string $query): object {}
	releaseSavepoint(string $name): $this {}
	rollback(): $this {}
	rollbackToSavepoint(string $name): $this {}
	savepoint(string $name): $this {}
	selectAll(string $table, object $fields, object $conditions, object $orderby, int $limit, int $offset, bool $indexed): object {}
	selectAllOfField(string $table, string $field, object $conditions, object $orderby, int $limit, int $offset): object {}
	selectOne(string $table, object $fields, object $conditions, object $orderby, bool $indexed): object {}
	selectSavepoint(string $name): object {}
	selectTransaction(): object {}
	setCharset(string $charset): $this {}
	update(string $table, object $data, object $conditions): int {}
	updateOrInsert(string $table, object $data, object $conditions): int {}
}
```

**Abstract SQL connection prototype.**

### Prototype

**[Base](#)**

## Methods


### `$this.begin()`


```code
$this.begin(): this
```

##### Returns

| Type | Value |
| --- | ---  |
| `$this` |  |




### `$this.close()`


Closes this connection and frees its associated resources.

```code
$this.close(): void
```




### `$this.commit()`


```code
$this.commit(): this
```

##### Returns

| Type | Value |
| --- | ---  |
| `$this` |  |




### `$this.countAffectedRows()`


```code
$this.countAffectedRows(): int
```

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |




### `$this.countRowsInTable()`


```code
$this.countRowsInTable(string $table): int
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| table | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |




### `$this.delete()`


```code
$this.delete(string $table, object $conditions): int
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| table | `string`  |  | "" |
| conditions | `object`  | [field: value, ...] | [] |

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |




### `$this.exists()`


```code
$this.exists(string $table, object $conditions): bool
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| table | `string`  |  | "" |
| conditions | `object`  | [field: value, ...] | [] |

##### Returns

| Type | Value |
| --- | ---  |
| `bool` |  |




### `$this.exit()`


Closes this connection and frees its associated resources for the purpose of contextualization.

```code
$this.exit(): void
```




### `$this.fetchAll()`


```code
$this.fetchAll(string $query, bool $indexed): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| query | `string`  |  | "" |
| indexed | `bool`  |  | false |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [row, ...] |




### `$this.fetchAllOfField()`


```code
$this.fetchAllOfField(string $query, int $index): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| query | `string`  |  | "" |
| index | `int`  |  | 0 |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [value, ...] |




### `$this.fetchOne()`


```code
$this.fetchOne(string $query, bool $indexed): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| query | `string`  |  | "" |
| indexed | `bool`  |  | false |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [field: value, ...] |
| `null` |  |




### `$this.getCharset()`


```code
$this.getCharset(): string
```

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `$this.getDatabaseName()`


```code
$this.getDatabaseName(): string
```

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `$this.getDatabaseSize()`


```code
$this.getDatabaseSize(): int
```

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |




### `$this.getLastInsertID()`


```code
$this.getLastInsertID(): int
```

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |




### `$this.getVersion()`


```code
$this.getVersion(): string
```

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `$this.insert()`


```code
$this.insert(string $table, object $data): int
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| table | `string`  |  | "" |
| data | `object`  | [field: value, ...] | [] |

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |




### `$this.listFieldsInTable()`


```code
$this.listFieldsInTable(string $table): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| table | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [field, ...] |




### `$this.listTables()`


```code
$this.listTables(): object
```

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [table, ...] |




### `$this.query()`


```code
$this.query(string $query): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| query | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | SQL.ResultSet |
| `null` |  |




### `$this.releaseSavepoint()`


```code
$this.releaseSavepoint(string $name): this
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| name | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `$this` |  |




### `$this.rollback()`


```code
$this.rollback(): this
```

##### Returns

| Type | Value |
| --- | ---  |
| `$this` |  |




### `$this.rollbackToSavepoint()`


```code
$this.rollbackToSavepoint(string $name): this
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| name | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `$this` |  |




### `$this.savepoint()`


```code
$this.savepoint(string $name): this
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| name | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `$this` |  |




### `$this.selectAll()`


```code
$this.selectAll(string $table, object $fields, object $conditions, object $orderby, int $limit, int $offset, bool $indexed): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| table | `string`  |  | "" |
| fields | `object`  | [field, ...] | [] |
| conditions | `object`  | [field: value, ...] | [] |
| orderby | `object`  | [field: descending, ...] | [] |
| limit | `int`  |  | 0 |
| offset | `int`  |  | 0 |
| indexed | `bool`  |  | false |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [row, ...] |




### `$this.selectAllOfField()`


```code
$this.selectAllOfField(string $table, string $field, object $conditions, object $orderby, int $limit, int $offset): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| table | `string`  |  | "" |
| field | `string`  |  | "" |
| conditions | `object`  | [field: value, ...] | [] |
| orderby | `object`  | [field: descending, ...] | [] |
| limit | `int`  |  | 0 |
| offset | `int`  |  | 0 |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [value, ...] |




### `$this.selectOne()`


```code
$this.selectOne(string $table, object $fields, object $conditions, object $orderby, bool $indexed): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| table | `string`  |  | "" |
| fields | `object`  | [field, ...] | [] |
| conditions | `object`  | [field: value, ...] | [] |
| orderby | `object`  | [field: descending, ...] | [] |
| indexed | `bool`  |  | false |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [field: value, ...] |
| `null` |  |




### `$this.selectSavepoint()`


```code
$this.selectSavepoint(string $name): @SQL.SavepointContext
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| name | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `@SQL.SavepointContext` |  |




### `$this.selectTransaction()`


```code
$this.selectTransaction(): @SQL.TransactionContext
```

##### Returns

| Type | Value |
| --- | ---  |
| `@SQL.TransactionContext` |  |




### `$this.setCharset()`


```code
$this.setCharset(string $charset): this
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| charset | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `$this` |  |




### `$this.update()`


```code
$this.update(string $table, object $data, object $conditions): int
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| table | `string`  |  | "" |
| data | `object`  | [field: value, ...] | [] |
| conditions | `object`  | [field: value, ...] | [] |

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |




### `$this.updateOrInsert()`


```code
$this.updateOrInsert(string $table, object $data, object $conditions): int
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| table | `string`  |  | "" |
| data | `object`  | [field: value, ...] | [] |
| conditions | `object`  | [field: value, ...] | [] |

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |
