Leaf PHP

Core
in package

Leaf Db [Core] ------------------------- Core functionality of leaf db.

Tags
author

Michael Darko

since
3.0
version
1.0.0

Table of Contents

Properties

$added  : mixed
Items to add to query results
$bindings  : mixed
Params bound to query
$config  : mixed
Config for leaf db
$connections  : mixed
List of connected db instances
$currentConnection  : string|null
Current connection to use for db
$eager  : mixed
Items to eager load
$errors  : mixed
Errors caught in leaf db
$hidden  : mixed
Items to hide from query results
$params  : mixed
Full list of params passed into leaf db
$query  : mixed
Actual query to run
$queryResult  : PDOStatement
Query result
$table  : mixed
Db table to peform operations on
$uniques  : mixed
Items which should be unique in db

Methods

__construct()  : mixed
Initialize leaf db with a database connection
addConnections()  : Core
Add a list of database connections
all()  : mixed
Alias for fetchAll
assoc()  : mixed
Alias for fetchAssoc
autoConnect()  : Core
Connect to database using environment variables
bind()  : self
Bind parameters to a query
close()  : void
Closes Db connection
column()  : mixed
Fetch column from results
config()  : mixed
Configure leaf db - syncs with leaf config
connect()  : Core
Connect to database
connection()  : mixed
Return the database connection
connectSync()  : PDO
Connect to database immediately
count()  : int
Get the current count of objects in query
debug()  : mixed
Get the current snapshot of leaf db internals
errors()  : array<string|int, mixed>
Return caught errors if any
execute()  : mixed
Execute a generated query
fetchAll()  : mixed
Fetch the items returned by query
fetchAssoc()  : mixed
Fetch the items returned by query
fetchObj()  : mixed
Fetch the items returned by query
get()  : mixed
Alias for fetchAll
lastInsertId()  : mixed
Returns the ID of the last inserted row or sequence value
load()  : Core
Alias for connect
obj()  : mixed
Alias for fetchObj
query()  : self
Manually create a database query
result()  : PDOStatement
Get raw result of last query
table()  : self
Set the current db table for operations
use()  : Core
Set the current connection to use for queries
clearState()  : mixed
Prepare leaf db to handle next query
copyState()  : mixed
Copy internal state
dsn()  : string
env()  : string|bool
Returns the value of the environment variable by using Leaf's `_env` primarily.

Properties

$added

Items to add to query results

protected mixed $added = []

$bindings

Params bound to query

protected mixed $bindings = []

$config

Config for leaf db

protected mixed $config = ['dbtype' => 'mysql', 'charset' => null, 'port' => '3306', 'unixSocket' => null, 'host' => '127.0.0.1', 'username' => 'root', 'password' => '', 'dbname' => '']

$connections

List of connected db instances

protected mixed $connections = []

$currentConnection

Current connection to use for db

protected string|null $currentConnection = null

$eager

Items to eager load

protected mixed $eager = []

$errors

Errors caught in leaf db

protected mixed $errors = []

$hidden

Items to hide from query results

protected mixed $hidden = []

$params

Full list of params passed into leaf db

protected mixed $params = []

$query

Actual query to run

protected mixed $query

$queryResult

Query result

protected PDOStatement $queryResult

$table

Db table to peform operations on

protected mixed $table = null

$uniques

Items which should be unique in db

protected mixed $uniques = []

Methods

__construct()

Initialize leaf db with a database connection

public __construct([string|array<string|int, mixed> $host = '' ][, string $dbname = '' ][, string $user = 'root' ][, string $password = '' ][, string $dbtype = 'mysql' ]) : mixed
Parameters
$host : string|array<string|int, mixed> = ''

Host Name or full config

$dbname : string = ''

Database name

$user : string = 'root'

Database username

$password : string = ''

Database password

$dbtype : string = 'mysql'

Type of database: mysql, postgres, sqlite, ...

addConnections()

Add a list of database connections

public addConnections(array<string|int, mixed> $connections[, string|null $default = null ]) : Core
Parameters
$connections : array<string|int, mixed>

List of database connections

$default : string|null = null
Return values
Core

all()

Alias for fetchAll

public all([mixed $type = 'assoc' ]) : mixed
Parameters
$type : mixed = 'assoc'

assoc()

Alias for fetchAssoc

public assoc() : mixed

autoConnect()

Connect to database using environment variables

public autoConnect([array<string|int, mixed> $pdoOptions = [] ]) : Core
Parameters
$pdoOptions : array<string|int, mixed> = []

Options for PDO connection

Return values
Core

bind()

Bind parameters to a query

public bind(mixed ...$bindings) : self
Parameters
$bindings : mixed
Return values
self

close()

Closes Db connection

public close() : void

column()

Fetch column from results

public column() : mixed

config()

Configure leaf db - syncs with leaf config

public config(mixed $name[, mixed $value = null ]) : mixed
Parameters
$name : mixed
$value : mixed = null

connect()

Connect to database

public connect([string|array<string|int, mixed> $host = '127.0.0.1' ][, string $dbname = '' ][, string $user = 'root' ][, string $password = '' ][, string $dbtype = 'mysql' ][, array<string|int, mixed> $pdoOptions = [] ]) : Core
Parameters
$host : string|array<string|int, mixed> = '127.0.0.1'

Host Name or full config

$dbname : string = ''

Database name

$user : string = 'root'

Database username

$password : string = ''

Database password

$dbtype : string = 'mysql'

Type of database: mysql, postgres, sqlite, ...

$pdoOptions : array<string|int, mixed> = []

Options for PDO connection

Return values
Core

connection()

Return the database connection

public connection([PDO|string|null $connection = null ]) : mixed
Parameters
$connection : PDO|string|null = null

Manual instance of PDO connection

connectSync()

Connect to database immediately

public connectSync([string|array<string|int, mixed> $host = '127.0.0.1' ][, string $dbname = '' ][, string $user = 'root' ][, string $password = '' ][, string $dbtype = 'mysql' ][, array<string|int, mixed> $pdoOptions = [] ]) : PDO
Parameters
$host : string|array<string|int, mixed> = '127.0.0.1'

Host Name or full config

$dbname : string = ''

Database name

$user : string = 'root'

Database username

$password : string = ''

Database password

$dbtype : string = 'mysql'

Type of database: mysql, postgres, sqlite, ...

$pdoOptions : array<string|int, mixed> = []

Options for PDO connection

Return values
PDO

count()

Get the current count of objects in query

public count() : int
Return values
int

debug()

Get the current snapshot of leaf db internals

public debug() : mixed

errors()

Return caught errors if any

public errors() : array<string|int, mixed>
Return values
array<string|int, mixed>

execute()

Execute a generated query

public execute() : mixed

fetchAll()

Fetch the items returned by query

public fetchAll([mixed $type = 'assoc' ]) : mixed
Parameters
$type : mixed = 'assoc'

fetchAssoc()

Fetch the items returned by query

public fetchAssoc() : mixed

fetchObj()

Fetch the items returned by query

public fetchObj() : mixed

get()

Alias for fetchAll

public get([mixed $type = 'assoc' ]) : mixed
Parameters
$type : mixed = 'assoc'

lastInsertId()

Returns the ID of the last inserted row or sequence value

public lastInsertId([string|null $name = null ]) : mixed
Parameters
$name : string|null = null

Name of the sequence object from which the ID should be returned.

load()

Alias for connect

public load([string|array<string|int, mixed> $host = '127.0.0.1' ][, string $dbname = '' ][, string $user = 'root' ][, string $password = '' ][, string $dbtype = 'mysql' ][, array<string|int, mixed> $pdoOptions = [] ]) : Core
Parameters
$host : string|array<string|int, mixed> = '127.0.0.1'

Host Name or full config

$dbname : string = ''

Database name

$user : string = 'root'

Database username

$password : string = ''

Database password

$dbtype : string = 'mysql'

Type of database: mysql, postgres, sqlite, ...

$pdoOptions : array<string|int, mixed> = []

Options for PDO connection

Return values
Core

obj()

Alias for fetchObj

public obj() : mixed

query()

Manually create a database query

public query(string $sql) : self
Parameters
$sql : string

Full db query

Return values
self

result()

Get raw result of last query

public result() : PDOStatement
Return values
PDOStatement

table()

Set the current db table for operations

public table(string $table) : self
Parameters
$table : string

Table to perform database operations on

Return values
self

use()

Set the current connection to use for queries

public use([string|null $connection = null ]) : Core
Parameters
$connection : string|null = null

The name of the connection to use

Return values
Core

clearState()

Prepare leaf db to handle next query

protected clearState() : mixed

copyState()

Copy internal state

protected copyState() : mixed

dsn()

protected dsn() : string
Return values
string

env()

Returns the value of the environment variable by using Leaf's `_env` primarily.

private env(string $name) : string|bool
Parameters
$name : string
Return values
string|bool

        
On this page

Search results