Menu

## Piql
in package
Uses InteractsWithTime

Piql.php : 53

Pionia Query Builder Provides base-strategy to perform all database queries in all RDBMS

This should not be interacted with from outside the core-framework, use Porm instead!

### Table of Contents

#### Properties

$application : PioniaApplication
  Pionia application instance
$error : string|null
  Error Message.
$errorInfo : array<string|int, mixed>|null
  The array of error information.
$pdo : PDO
  The PDO object.
$prettyQuery : string|null
  Current readable Query
$queryString : string
  The last query string was generated in test mode.
$returnId : string
  The returned id for the insert.
$type : string
  The type of database.
$debugLogging : bool
  Determine should save debug logging.
$debugLogs : array<string|int, mixed>
  The array of logs for debugging.
$debugMode : bool
  Determine is in debug mode.
$dsn : string
  The DSN connection string.
$guid : int
  The unique global id.
$logging : bool
  Determine should log the query or not.
$logs : array<string|int, mixed>
  The array of logs.
$prefix : string
  Table prefix.
$statement : PDOStatement|null
  The PDO statement object.
$testMode : bool
  Determine is in test mode.

#### Methods

__construct() : mixed
  DatabaseConnector the database.
action() : void
  Start a transaction.
avg() : string
avg() : string
avg() : string|null
  Calculate the average value of the column.
beginDebug() : void
  Enable debug logging mode.
columnQuote() : string
  Quote column name for use in a query.
count() : int
count() : int|null
  Count the number of rows from the table.
create() : PDOStatement|null
  Create a table.
debug() : Db
  Enable debug mode and output readable statement string.
debugLog() : void
  Disable debug logging and return all readable statements.
delete() : PDOStatement|null
  Delete data from the table.
drop() : PDOStatement|null
  Drop a table.
exec() : PDOStatement|null
  Execute the raw statement.
get() : mixed
get() : mixed
  Get only one record from the table.
has() : bool
has() : bool
  Determine whether the target data existed from the table.
id() : string|null
  Return the ID for the last inserted row.
info() : array<string|int, mixed>
  Get information about the database connection.
insert() : PDOStatement|null
  Insert one or more records into the table.
last() : string|null
  Return the last performed statement.
log() : array<string|int, string>
  Return all executed statements.
max() : string
max() : string
max() : string|null
  Get the maximum value of the column.
min() : string
min() : string
min() : string|null
  Get the minimum value of the column.
query() : PDOStatement|null
  Execute customized raw statement.
quote() : string
  Quote a string for use in a query.
rand() : mixed
rand() : array<string|int, mixed>
  Randomly fetch data from the table.
raw() : Db::raw
  Build a raw object.
replace() : PDOStatement|null
  Replace old data with a new one.
select() : array<string|int, mixed>
select() : array<string|int, mixed>
select() : array<string|int, mixed>
select() : array<string|int, mixed>
select() : array<string|int, mixed>|null
  Select data from the table.
sum() : string
sum() : string
sum() : string|null
  Calculate the total value of the column.
tableQuote() : string
  Quote table name for use in a query.
update() : PDOStatement|null
  Modify data from the table.
availableAt() : int
  Get the "available at" UNIX timestamp.
buildJoin() : string
  Build the join statement.
buildRaw() : string|null
  Generate the actual query from the raw object.
columnMap() : array<string|int, mixed>
  Mapping columns for the stack.
columnPush() : string
  Build the statement part for the column stack.
currentTime() : int
  Get the current system time as a UNIX timestamp.
dataImplode() : string
  Implode the Where conditions.
dataMap() : void
  Mapping the data from the table.
generate() : string
  Generate readable statement.
isJoin() : bool
  Determine the array with join syntax.
isRaw() : bool
  Finds whether the object is raw.
mapKey() : string
  Generate a new map key for the placeholder.
parseDateInterval() : DateInterval|DateTimeInterface|int
  If the given value is an interval, convert it to a DateTime instance.
runTimeForHumans() : string
  Given a start time, format the total run time for human readability.
secondsUntil() : int
  Get the number of seconds until the given DateTime.
selectContext() : string
  Build statement for the select query.
typeMap() : array<string|int, mixed>
  Mapping the type name as PDO data type.
whereClause() : string
  Build the where clause.
aggregate() : string|null
  Build for the aggregate function.
returningQuery() : PDOStatement|null
  Build and execute returning query.

### Properties

#### $application

Piql.php : 178

Pionia application instance

`public PioniaApplication $application`

#### $error

Piql.php : 165

Error Message.

`public string|null $error = null`

#### $errorInfo

Piql.php : 172

The array of error information.

`public array<string|int, mixed>|null $errorInfo = null`

#### $pdo

Piql.php : 61

The PDO object.

`public PDO $pdo`

#### $prettyQuery

Piql.php : 67

Current readable Query

`public string|null $prettyQuery = null`

#### $queryString

Piql.php : 123

The last query string was generated in test mode.

`public string $queryString`

#### $returnId

Piql.php : 158

The returned id for the insert.

`public string $returnId = ''`

#### $type

Piql.php : 74

The type of database.

`public string $type`

#### $debugLogging

Piql.php : 137

Determine should save debug logging.

`protected bool $debugLogging = false`

#### $debugLogs

Piql.php : 144

The array of logs for debugging.

`protected array<string|int, mixed> $debugLogs = []`

#### $debugMode

Piql.php : 130

Determine is in debug mode.

`protected bool $debugMode = false`

#### $dsn

Piql.php : 95

The DSN connection string.

`protected string $dsn`

#### $guid

Piql.php : 151

The unique global id.

`protected int $guid = 0`

#### $logging

Piql.php : 109

Determine should log the query or not.

`protected bool $logging = false`

#### $logs

Piql.php : 102

The array of logs.

`protected array<string|int, mixed> $logs = []`

#### $prefix

Piql.php : 81

Table prefix.

`protected string $prefix`

#### $statement

Piql.php : 88

The PDO statement object.

`protected PDOStatement|null $statement`

#### $testMode

Piql.php : 116

Determine is in test mode.

`protected bool $testMode = false`

### Methods

#### __construct()

Piql.php : 204

DatabaseConnector the database.

`public __construct(Connection $connection) : mixed`

    $database = new Db($app, [
         // required
         'type' => 'mysql',
         'database' => 'name',
         'host' => 'localhost',
         'username' => 'your_username',
         'password' => 'your_password',

         // [optional]
         'charset' => 'utf8mb4',
         'port' => 3306,
         'prefix' => 'PREFIX_'
    ]);

##### Parameters

$connection : Connection

##### Tags

link
  https://medoo.in/api/new
codeCoverageIgnore

#### action()

Piql.php : 1841

Start a transaction.

`public action(callable $actions) : void`

##### Parameters

$actions : callable

##### Tags

codeCoverageIgnore

#### avg()

Piql.php : 0
`public avg(string $table, string $column) : string`

##### Parameters

$table : string
$column : string

##### Return values

string

#### avg()

Piql.php : 0
`public avg(string $table, string $column, array<string|int, mixed> $where) : string`

##### Parameters

$table : string
$column : string
$where : array<string|int, mixed>

##### Return values

string

#### avg()

Piql.php : 1787

Calculate the average value of the column.

`public avg(string $table, array<string|int, mixed> $join[, string $column = null ][, array<string|int, mixed> $where = null ]) : string|null`

##### Parameters

$table : string
$join : array<string|int, mixed>
$column : string = null
$where : array<string|int, mixed> = null

##### Return values

string|null

#### beginDebug()

Piql.php : 1902

Enable debug logging mode.

`public beginDebug() : void`

##### Tags

codeCoverageIgnore

#### columnQuote()

Piql.php : 458

Quote column name for use in a query.

`public columnQuote(string $column) : string`

##### Parameters

$column : string

##### Return values

string

#### count()

Piql.php : 0
`public count(string $table, array<string|int, mixed> $where) : int`

##### Parameters

$table : string
$where : array<string|int, mixed>

##### Return values

int

#### count()

Piql.php : 1773

Count the number of rows from the table.

`public count(string $table[, array<string|int, mixed> $join = null ][, string $column = null ][, array<string|int, mixed> $where = null ]) : int|null`

##### Parameters

$table : string
$join : array<string|int, mixed> = null
$column : string = null
$where : array<string|int, mixed> = null

##### Return values

int|null

#### create()

Piql.php : 1266

Create a table.

`public create(string $table, array<string|int, mixed> $columns[, array<string|int, mixed> $options = null ]) : PDOStatement|null`

##### Parameters

$table : string
$columns : array<string|int, mixed>

  Columns definition.

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

  Additional table options for creating a table.

##### Return values

PDOStatement|null

#### debug()

Piql.php : 1889

Enable debug mode and output readable statement string.

`public debug() : Db`

##### Tags

codeCoverageIgnore

##### Return values

Db

#### debugLog()

Piql.php : 1914

Disable debug logging and return all readable statements.

`public debugLog() : void`

##### Tags

codeCoverageIgnore

#### delete()

Piql.php : 1582

Delete data from the table.

`public delete(string $table, array<string|int, mixed>|Raw $where) : PDOStatement|null`

##### Parameters

$table : string
$where : array<string|int, mixed>|Raw

##### Return values

PDOStatement|null

#### drop()

Piql.php : 1311

Drop a table.

`public drop(string $table) : PDOStatement|null`

##### Parameters

$table : string

##### Return values

PDOStatement|null

#### exec()

Piql.php : 248

Execute the raw statement.

`public exec(string $statement[, array<string|int, mixed> $map = [] ][, callable $callback = null ]) : PDOStatement|null`

##### Parameters

$statement : string

  The SQL statement.

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

  The array of input parameters value for prepared statement.

$callback : callable = null

##### Tags

codeCoverageIgnore

##### Return values

PDOStatement|null

#### get()

Piql.php : 0
`public get(string $table, array<string|int, mixed>|string $columns, array<string|int, mixed> $where) : mixed`

##### Parameters

$table : string
$columns : array<string|int, mixed>|string
$where : array<string|int, mixed>

#### get()

Piql.php : 1631

Get only one record from the table.

`public get(string $table[, array<string|int, mixed> $join = null ][, array<string|int, mixed>|string $columns = null ][, array<string|int, mixed> $where = null ]) : mixed`

##### Parameters

$table : string
$join : array<string|int, mixed> = null
$columns : array<string|int, mixed>|string = null
$where : array<string|int, mixed> = null

#### has()

Piql.php : 0
`public has(string $table, array<string|int, mixed> $where) : bool`

##### Parameters

$table : string
$where : array<string|int, mixed>

##### Return values

bool

#### has()

Piql.php : 1686

Determine whether the target data existed from the table.

`public has(string $table, array<string|int, mixed> $join[, array<string|int, mixed> $where = null ]) : bool`

##### Parameters

$table : string
$join : array<string|int, mixed>
$where : array<string|int, mixed> = null

##### Return values

bool

#### id()

Piql.php : 1868

Return the ID for the last inserted row.

`public id([string $name = null ]) : string|null`

##### Parameters

$name : string = null

##### Tags

codeCoverageIgnore

##### Return values

string|null

#### info()

Piql.php : 1961

Get information about the database connection.

`public info() : array<string|int, mixed>`

##### Tags

codeCoverageIgnore

##### Return values

array<string|int, mixed>

#### insert()

Piql.php : 1405

Insert one or more records into the table.

`public insert(string $table, array<string|int, mixed> $values[, string $primaryKey = null ]) : PDOStatement|null`

##### Parameters

$table : string
$values : array<string|int, mixed>
$primaryKey : string = null

##### Return values

PDOStatement|null

#### last()

Piql.php : 1928

Return the last performed statement.

`public last() : string|null`

##### Tags

codeCoverageIgnore

##### Return values

string|null

#### log()

Piql.php : 1945

Return all executed statements.

`public log() : array<string|int, string>`

##### Tags

codeCoverageIgnore

##### Return values

array<string|int, string>

#### max()

Piql.php : 0
`public max(string $table, string $column) : string`

##### Parameters

$table : string
$column : string

##### Return values

string

#### max()

Piql.php : 0
`public max(string $table, string $column, array<string|int, mixed> $where) : string`

##### Parameters

$table : string
$column : string
$where : array<string|int, mixed>

##### Return values

string

#### max()

Piql.php : 1801

Get the maximum value of the column.

`public max(string $table, array<string|int, mixed> $join[, string $column = null ][, array<string|int, mixed> $where = null ]) : string|null`

##### Parameters

$table : string
$join : array<string|int, mixed>
$column : string = null
$where : array<string|int, mixed> = null

##### Return values

string|null

#### min()

Piql.php : 0
`public min(string $table, string $column) : string`

##### Parameters

$table : string
$column : string

##### Return values

string

#### min()

Piql.php : 0
`public min(string $table, string $column, array<string|int, mixed> $where) : string`

##### Parameters

$table : string
$column : string
$where : array<string|int, mixed>

##### Return values

string

#### min()

Piql.php : 1815

Get the minimum value of the column.

`public min(string $table, array<string|int, mixed> $join[, string $column = null ][, array<string|int, mixed> $where = null ]) : string|null`

##### Parameters

$table : string
$join : array<string|int, mixed>
$column : string = null
$where : array<string|int, mixed> = null

##### Return values

string|null

#### query()

Piql.php : 232

Execute customized raw statement.

`public query(string $statement[, array<string|int, mixed> $map = [] ]) : PDOStatement|null`

##### Parameters

$statement : string

  The raw SQL statement.

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

  The array of input parameters value for prepared statement.

##### Return values

PDOStatement|null

#### quote()

Piql.php : 428

Quote a string for use in a query.

`public quote(string $string) : string`

##### Parameters

$string : string

##### Return values

string

#### rand()

Piql.php : 0
`public rand(string $table, array<string|int, mixed>|string $column, array<string|int, mixed> $where) : mixed`

##### Parameters

$table : string
$column : array<string|int, mixed>|string
$where : array<string|int, mixed>

#### rand()

Piql.php : 1718

Randomly fetch data from the table.

`public rand(string $table[, array<string|int, mixed> $join = null ][, array<string|int, mixed>|string $columns = null ][, array<string|int, mixed> $where = null ]) : array<string|int, mixed>`

##### Parameters

$table : string
$join : array<string|int, mixed> = null
$columns : array<string|int, mixed>|string = null
$where : array<string|int, mixed> = null

##### Return values

array<string|int, mixed>

#### raw()

Piql.php : 361

Build a raw object.

`public static raw(string $string[, array<string|int, mixed> $map = [] ]) : Db::raw`

##### Parameters

$string : string

  The raw string.

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

  The array of mapping data for the raw string.

##### Return values

Db::raw

#### replace()

Piql.php : 1597

Replace old data with a new one.

`public replace(string $table, array<string|int, mixed> $columns[, array<string|int, mixed> $where = null ]) : PDOStatement|null`

##### Parameters

$table : string
$columns : array<string|int, mixed>
$where : array<string|int, mixed> = null

##### Return values

PDOStatement|null

#### select()

Piql.php : 0
`public select(string $table, array<string|int, mixed> $columns, callable $callback) : array<string|int, mixed>`

##### Parameters

$table : string
$columns : array<string|int, mixed>
$callback : callable

##### Return values

array<string|int, mixed>

#### select()

Piql.php : 0
`public select(string $table, array<string|int, mixed> $columns, array<string|int, mixed> $where, callable $callback) : array<string|int, mixed>`

##### Parameters

$table : string
$columns : array<string|int, mixed>
$where : array<string|int, mixed>
$callback : callable

##### Return values

array<string|int, mixed>

#### select()

Piql.php : 0
`public select(string $table, array<string|int, mixed> $columns, array<string|int, mixed> $where) : array<string|int, mixed>`

##### Parameters

$table : string
$columns : array<string|int, mixed>
$where : array<string|int, mixed>

##### Return values

array<string|int, mixed>

#### select()

Piql.php : 0
`public select(string $table, array<string|int, mixed> $join, array<string|int, mixed> $columns, array<string|int, mixed> $where, callable $callback) : array<string|int, mixed>`

##### Parameters

$table : string
$join : array<string|int, mixed>
$columns : array<string|int, mixed>
$where : array<string|int, mixed>
$callback : callable

##### Return values

array<string|int, mixed>

#### select()

Piql.php : 1325

Select data from the table.

`public select(string $table, array<string|int, mixed> $join[, array<string|int, mixed>|string $columns = null ][, array<string|int, mixed> $where = null ]) : array<string|int, mixed>|null`

##### Parameters

$table : string
$join : array<string|int, mixed>
$columns : array<string|int, mixed>|string = null
$where : array<string|int, mixed> = null

##### Return values

array<string|int, mixed>|null

#### sum()

Piql.php : 0
`public sum(string $table, string $column) : string`

##### Parameters

$table : string
$column : string

##### Return values

string

#### sum()

Piql.php : 0
`public sum(string $table, string $column, array<string|int, mixed> $where) : string`

##### Parameters

$table : string
$column : string
$where : array<string|int, mixed>

##### Return values

string

#### sum()

Piql.php : 1829

Calculate the total value of the column.

`public sum(string $table, array<string|int, mixed> $join[, string $column = null ][, array<string|int, mixed> $where = null ]) : string|null`

##### Parameters

$table : string
$join : array<string|int, mixed>
$column : string = null
$where : array<string|int, mixed> = null

##### Return values

string|null

#### tableQuote()

Piql.php : 443

Quote table name for use in a query.

`public tableQuote(string $table) : string`

##### Parameters

$table : string

##### Return values

string

#### update()

Piql.php : 1508

Modify data from the table.

`public update(string $table, array<string|int, mixed> $data[, array<string|int, mixed> $where = null ]) : PDOStatement|null`

##### Parameters

$table : string
$data : array<string|int, mixed>
$where : array<string|int, mixed> = null

##### Return values

PDOStatement|null

#### availableAt()

InteractsWithTime.php : 34

Get the "available at" UNIX timestamp.

`protected availableAt([DateInterval|DateTimeInterface|int $delay = 0 ]) : int`

##### Parameters

$delay : DateInterval|DateTimeInterface|int = 0

##### Return values

int

#### buildJoin()

Piql.php : 1008

Build the join statement.

`protected buildJoin(string $table, array<string|int, mixed> $join, array<string|int, mixed> &$map) : string`

##### Parameters

$table : string
$join : array<string|int, mixed>
$map : array<string|int, mixed>

##### Return values

string

#### buildRaw()

Piql.php : 389

Generate the actual query from the raw object.

`protected buildRaw(mixed $raw, array<string|int, mixed> &$map) : string|null`

##### Parameters

$raw : mixed
$map : array<string|int, mixed>

##### Return values

string|null

#### columnMap()

Piql.php : 1078

Mapping columns for the stack.

`protected columnMap(array<string|int, mixed>|string $columns, array<string|int, mixed> &$stack, bool $root) : array<string|int, mixed>`

##### Parameters

$columns : array<string|int, mixed>|string
$stack : array<string|int, mixed>
$root : bool

##### Return values

array<string|int, mixed>

#### columnPush()

Piql.php : 506

Build the statement part for the column stack.

`protected columnPush(array<string|int, mixed>|string &$columns, array<string|int, mixed> &$map, bool $root[, bool $isJoin = false ]) : string`

##### Parameters

$columns : array<string|int, mixed>|string
$map : array<string|int, mixed>
$root : bool
$isJoin : bool = false

##### Return values

string

#### currentTime()

InteractsWithTime.php : 63

Get the current system time as a UNIX timestamp.

`protected currentTime() : int`

##### Return values

int

#### dataImplode()

Piql.php : 574

Implode the Where conditions.

`protected dataImplode(array<string|int, mixed> $data, array<string|int, mixed> &$map, string $conjunctor) : string`

##### Parameters

$data : array<string|int, mixed>
$map : array<string|int, mixed>
$conjunctor : string

##### Return values

string

#### dataMap()

Piql.php : 1126

Mapping the data from the table.

`protected dataMap(array<string|int, mixed> $data, array<string|int, mixed> $columns, array<string|int, mixed> $columnMap, array<string|int, mixed> &$stack, bool $root[, array<string|int, mixed> &$result = null ]) : void`

##### Parameters

$data : array<string|int, mixed>
$columns : array<string|int, mixed>
$columnMap : array<string|int, mixed>
$stack : array<string|int, mixed>
$root : bool
$result : array<string|int, mixed> = null

##### Tags

codeCoverageIgnore

#### generate()

Piql.php : 324

Generate readable statement.

`protected generate(string $statement, array<string|int, mixed> $map) : string`

##### Parameters

$statement : string
$map : array<string|int, mixed>

##### Tags

codeCoverageIgnore

##### Return values

string

#### isJoin()

Piql.php : 981

Determine the array with join syntax.

`protected isJoin(mixed $join) : bool`

##### Parameters

$join : mixed

##### Return values

bool

#### isRaw()

Piql.php : 377

Finds whether the object is raw.

`protected isRaw(object $object) : bool`

##### Parameters

$object : object

##### Return values

bool

#### mapKey()

Piql.php : 220

Generate a new map key for the placeholder.

`protected mapKey() : string`

##### Return values

string

#### parseDateInterval()

InteractsWithTime.php : 49

If the given value is an interval, convert it to a DateTime instance.

`protected parseDateInterval(DateInterval|DateTimeInterface|int $delay) : DateInterval|DateTimeInterface|int`

##### Parameters

$delay : DateInterval|DateTimeInterface|int

##### Return values

DateInterval|DateTimeInterface|int

#### runTimeForHumans()

InteractsWithTime.php : 76

Given a start time, format the total run time for human readability.

`protected runTimeForHumans(float $startTime[, float|null $endTime = null ]) : string`

##### Parameters

$startTime : float
$endTime : float|null = null

##### Tags

throws
  Exception

##### Return values

string

#### secondsUntil()

InteractsWithTime.php : 19

Get the number of seconds until the given DateTime.

`protected secondsUntil(DateInterval|DateTimeInterface|int $delay) : int`

##### Parameters

$delay : DateInterval|DateTimeInterface|int

##### Return values

int

#### selectContext()

Piql.php : 909

Build statement for the select query.

`protected selectContext(string $table, array<string|int, mixed> &$map, array<string|int, mixed>|string $join[, array<string|int, mixed>|string &$columns = null ][, array<string|int, mixed> $where = null ][, string $columnFn = null ]) : string`

##### Parameters

$table : string
$map : array<string|int, mixed>
$join : array<string|int, mixed>|string
$columns : array<string|int, mixed>|string = null
$where : array<string|int, mixed> = null
$columnFn : string = null

##### Return values

string

#### typeMap()

Piql.php : 476

Mapping the type name as PDO data type.

`protected typeMap(mixed $value, string $type) : array<string|int, mixed>`

##### Parameters

$value : mixed
$type : string

##### Return values

array<string|int, mixed>

#### whereClause()

Piql.php : 764

Build the where clause.

`protected whereClause(array<string|int, mixed>|null $where, array<string|int, mixed> &$map) : string`

##### Parameters

$where : array<string|int, mixed>|null
$map : array<string|int, mixed>

##### Return values

string

#### aggregate()

Piql.php : 1749

Build for the aggregate function.

`private aggregate(string $type, string $table[, array<string|int, mixed> $join = null ][, string $column = null ][, array<string|int, mixed> $where = null ]) : string|null`

##### Parameters

$type : string
$table : string
$join : array<string|int, mixed> = null
$column : string = null
$where : array<string|int, mixed> = null

##### Return values

string|null

#### returningQuery()

Piql.php : 1231

Build and execute returning query.

`private returningQuery(string $query, array<string|int, mixed> &$map, array<string|int, mixed> &$data) : PDOStatement|null`

##### Parameters

$query : string
$map : array<string|int, mixed>
$data : array<string|int, mixed>

##### Return values

PDOStatement|null

## Search results