Class Go
Database
class Database {
- public object $bridge;
- public string $id;
- public bool $is_readonly;
- public function __construct(string $name);
- public function begin(): mixed;
- public function close(): mixed;
- public function commit(): mixed;
- public function connect(): mixed;
- public function get(string $query, mixed ...$args): mixed;
- public function get_all(string $query, mixed ...$args): mixed;
- public function insert(string $table, mixed $value): mixed;
- public function insert_id(): mixed;
- public function query(string $query, mixed ...$args): mixed;
- public function replace(string $table, mixed $value): mixed;
- public function rollback(): mixed;
- public function rows_affected(): mixed;
- public function update(string $table, mixed $value, mixed ...$key_columns): mixed;
- public static connections(...);
- public static register(...);
}
Description
Database is the database client scripts query. $name selects a connection registered with the host; the constructor throws when the name is not registered or the pool fails to open.
Database is a class phpscript declares.
$object = new Database($name);
Properties
public object $bridge-
The go field
Bridge. public string $id-
The go field
ID. public bool $is_readonly-
IsReadonly restricts the client to statements that only read. The flag belongs to the client and not the connection: PHP reads and writes it as `$db->is_readonly`, and it lives as long as the client does, which for a served request is the request.
It refuses insert(), replace() and update() outright, and refuses any statement passed to query(), get() or get_all() that does not start with a read-only keyword (see readOnlyStatements). Transactions, connection pinning and the result accessors stay available, since a read-only transaction is a read.
The restriction is a boundary for the code holding this client, and no sandbox around the script: the script that set it can unset it. A connection that must not write belongs to a database user without the grant to, and this marks the code that must not write.
The go field
IsReadonly.
Methods
public function begin(): mixed-
begin starts a transaction and opens the span measuring it. The span stays open until Commit or Rollback and a transaction is one region in the trace and no open marker and close marker to pair up.
The go method
Begin. public function close(): mixed-
close releases an exclusive connection back to the pool.
The go method
Close. public function commit(): mixed-
commit commits the active transaction and ends its span.
The go method
Commit. public function connect(): mixed-
connect reserves an exclusive connection from the pool.
The go method
Connect. public function get(string $query, mixed ...$args): mixed-
get returns the first result row, or false when the query matches no rows.
A row is a native map: foreach walks it, $row["col"] indexes it, $row["extra"] = 1 writes to it and unset($row["col"]) takes a column out of it. A map carries no column order and `foreach ($row as $column => $value)` visits columns in arbitrary order; a script that needs a stable order names its columns in the SELECT and indexes them.
The go method
Get. public function get_all(string $query, mixed ...$args): mixed-
get_all returns all result rows. See Get for the row representation.
The go method
GetAll. public function insert(string $table, mixed $value): mixed-
insert inserts a dynamically typed named value.
The go method
Insert. public function insert_id(): mixed-
insert_id returns the ID generated by the last insert.
The go method
InsertID. public function query(string $query, mixed ...$args): mixed-
query executes a statement with dynamically typed arguments.
The go method
Query. public function replace(string $table, mixed $value): mixed-
replace replaces a row using a dynamically typed named value.
The go method
Replace. public function rollback(): mixed-
rollback rolls back the active transaction and ends its span.
The go method
Rollback. public function rows_affected(): mixed-
rows_affected returns the affected row count from the last write.
The go method
RowsAffected. public function update(string $table, mixed $value, mixed ...$key_columns): mixed-
update updates a row using dynamically typed named values and key columns.
The go method
Update.
Static methods
Binding
- The go type
github.com/titpetric/phpscript/stdlib/database.Database. - Registered by the package
github.com/titpetric/phpscript/stdlib/database. - Built on
github.com/titpetric/phpscript/stdlib/database.Database.