Menu

## Database extends Db
in package

Database.php : 25

### Table of Contents

#### Properties

$error : string|null
  Error Message.
$errorInfo : array<string|int, mixed>|null
  The array of error information.
$options : array<string|int, mixed>
  These are the Medoo Object options to pass along
$pdo : PDO
  The PDO object.
$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
  The PDO statement object.
$testMode : bool
  Determine is in test mode.

#### Methods

__construct() : Db
  Connect the database.
__destruct() : mixed
action() : void
  Start a transaction.
avg() : string|null
  Calculate the average value of the column.
avg() : string
avg() : string
beginDebug() : void
  Enable debug logging mode.
builder() : Database
columnQuote() : string
  Quote column name for use in a query.
count() : int|null
  Count the number of rows from the table.
count() : int
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 only one record from the table.
get() : mixed
has() : bool
  Determine whether the target data existed from the table.
has() : bool
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.
lastId() : string|null
  Returns the id of the last inserted row
log() : array<string|int, string>
  Return all executed statements.
max() : string|null
  Get the maximum value of the column.
max() : string
max() : string
min() : string|null
  Get the minimum value of the column.
min() : string
min() : string
pdo() : PDO
  Returns the underlying pdo object From this, you can do anything you want with the pdo object
query() : PDOStatement|null
  Execute customized raw statement.
quote() : string
  Quote a string for use in a query.
rand() : array<string|int, mixed>
  Randomly fetch data from the table.
rand() : mixed
raw() : Db::raw
  Build a raw object.
replace() : PDOStatement|null
  Replace old data with a new one.
select() : array<string|int, mixed>|null
  Select data from the table.
select() : array<string|int, mixed>
select() : null
select() : null
select() : null
sum() : string|null
  Calculate the total value of the column.
sum() : string
sum() : string
tableQuote() : string
  Quote table name for use in a query.
update() : PDOStatement|null
  Modify data from the table.
use() : Database
  This is a static method to use a Database connection. It will return a new Database instance with the connection passed.
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.
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.
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.
configure() : Database
  Resolves the Database connection to use. If the connection is passed, it will use that connection. If the options are passed, it will use those options. If the pdo is passed, it will use that pdo.
returningQuery() : PDOStatement|null
  Build and execute returning query.

### Properties

#### $error

Db.php : 150

Error Message.

`public string|null $error = null`

#### $errorInfo

Db.php : 157

The array of error information.

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

#### $options

Database.php : 31

These are the Medoo Object options to pass along

`public array<string|int, mixed> $options = []`

#### $pdo

Db.php : 52

The PDO object.

`public PDO $pdo`

#### $queryString

Db.php : 108

The last query string was generated in test mode.

`public string $queryString`

#### $returnId

Db.php : 143

The returned id for the insert.

`public string $returnId = ''`

#### $type

Db.php : 59

The type of database.

`public string $type`

#### $debugLogging

Db.php : 122

Determine should save debug logging.

`protected bool $debugLogging = false`

#### $debugLogs

Db.php : 129

The array of logs for debugging.

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

#### $debugMode

Db.php : 115

Determine is in debug mode.

`protected bool $debugMode = false`

#### $dsn

Db.php : 80

The DSN connection string.

`protected string $dsn`

#### $guid

Db.php : 136

The unique global id.

`protected int $guid = 0`

#### $logging

Db.php : 94

Determine should log the query or not.

`protected bool $logging = false`

#### $logs

Db.php : 87

The array of logs.

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

#### $prefix

Db.php : 66

Table prefix.

`protected string $prefix`

#### $statement

Db.php : 73

The PDO statement object.

`protected PDOStatement $statement`

#### $testMode

Db.php : 101

Determine is in test mode.

`protected bool $testMode = false`

### Methods

#### __construct()

Db.php : 185

Connect the database.

`public __construct(array<string|int, mixed> $options) : Db`

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

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

##### Parameters

$options : array<string|int, mixed>

  Connection options

##### Tags

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

##### Return values

Db

#### __destruct()

Database.php : 146
`public __destruct() : mixed`

#### action()

Db.php : 2093

Start a transaction.

`public action(callable $actions) : void`

##### Parameters

$actions : callable

##### Tags

codeCoverageIgnore

#### avg()

Db.php : 2039

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

#### avg()

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

##### Parameters

$table : string
$column : string

##### Return values

string

#### avg()

Db.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

#### beginDebug()

Db.php : 2154

Enable debug logging mode.

`public beginDebug() : void`

##### Tags

codeCoverageIgnore

#### builder()

Database.php : 106
`public static builder([string|null $databaseConnection = null ][, mixed $options = null ][, PDO|null $pdo = null ]) : Database`

##### Parameters

$databaseConnection : string|null = null
$options : mixed = null
$pdo : PDO|null = null

##### Tags

throws
  Exception

##### Return values

Database

#### columnQuote()

Db.php : 710

Quote column name for use in a query.

`public columnQuote(string $column) : string`

##### Parameters

$column : string

##### Return values

string

#### count()

Db.php : 2025

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

#### count()

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

##### Parameters

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

##### Return values

int

#### create()

Db.php : 1518

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()

Db.php : 2141

Enable debug mode and output readable statement string.

`public debug() : Db`

##### Tags

codeCoverageIgnore

##### Return values

Db

#### debugLog()

Db.php : 2166

Disable debug logging and return all readable statements.

`public debugLog() : void`

##### Tags

codeCoverageIgnore

#### delete()

Db.php : 1834

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()

Db.php : 1563

Drop a table.

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

##### Parameters

$table : string

##### Return values

PDOStatement|null

#### exec()

Db.php : 497

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()

Db.php : 1883

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

#### get()

Db.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>

#### has()

Db.php : 1938

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

#### has()

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

##### Parameters

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

##### Return values

bool

#### id()

Db.php : 2120

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()

Db.php : 2213

Get information about the database connection.

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

##### Tags

codeCoverageIgnore

##### Return values

array<string|int, mixed>

#### insert()

Db.php : 1657

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()

Db.php : 2180

Return the last performed statement.

`public last() : string|null`

##### Tags

codeCoverageIgnore

##### Return values

string|null

#### lastId()

Database.php : 116

Returns the id of the last inserted row

`public lastId() : string|null`

##### Return values

string|null

#### log()

Db.php : 2197

Return all executed statements.

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

##### Tags

codeCoverageIgnore

##### Return values

array<string|int, string>

#### max()

Db.php : 2053

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

#### max()

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

##### Parameters

$table : string
$column : string

##### Return values

string

#### max()

Db.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

#### min()

Db.php : 2067

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

#### min()

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

##### Parameters

$table : string
$column : string

##### Return values

string

#### min()

Db.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

#### pdo()

Database.php : 130

Returns the underlying pdo object From this, you can do anything you want with the pdo object

`public pdo() : PDO`

##### Tags

example

      $start = $this->pdo()->beginTransaction();

see
  https://medoo.in/api/pdo

  for more information on the pdo object

##### Return values

PDO

#### query()

Db.php : 481

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()

Db.php : 680

Quote a string for use in a query.

`public quote(string $string) : string`

##### Parameters

$string : string

##### Return values

string

#### rand()

Db.php : 1970

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>

#### rand()

Db.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>

#### raw()

Db.php : 613

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()

Db.php : 1849

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()

Db.php : 1577

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

#### select()

Db.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()

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

##### Parameters

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

##### Return values

null

#### select()

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

##### Parameters

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

##### Return values

null

#### select()

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

##### Parameters

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

##### Return values

null

#### sum()

Db.php : 2081

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

#### sum()

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

##### Parameters

$table : string
$column : string

##### Return values

string

#### sum()

Db.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

#### tableQuote()

Db.php : 695

Quote table name for use in a query.

`public tableQuote(string $table) : string`

##### Parameters

$table : string

##### Return values

string

#### update()

Db.php : 1760

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

#### use()

Database.php : 141

This is a static method to use a Database connection. It will return a new Database instance with the connection passed.

`public static use([string|null $databaseConnection = 'db' ]) : Database`

##### Parameters

$databaseConnection : string|null = 'db'

##### Tags

throws
  Exception

##### Return values

Database

#### buildJoin()

Db.php : 1260

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()

Db.php : 641

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()

Db.php : 1330

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()

Db.php : 758

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

#### dataImplode()

Db.php : 826

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()

Db.php : 1378

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()

Db.php : 576

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()

Db.php : 1233

Determine the array with join syntax.

`protected isJoin(mixed $join) : bool`

##### Parameters

$join : mixed

##### Return values

bool

#### isRaw()

Db.php : 629

Finds whether the object is raw.

`protected isRaw(object $object) : bool`

##### Parameters

$object : object

##### Return values

bool

#### mapKey()

Db.php : 469

Generate a new map key for the placeholder.

`protected mapKey() : string`

##### Return values

string

#### selectContext()

Db.php : 1161

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()

Db.php : 728

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()

Db.php : 1016

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()

Db.php : 2001

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

#### configure()

Database.php : 76

Resolves the Database connection to use. If the connection is passed, it will use that connection. If the options are passed, it will use those options. If the pdo is passed, it will use that pdo.

`private static configure([mixed $connection = null ][, mixed $options = null ][, mixed $pdo = null ]) : Database`

If all are passed, it will use the pdo connection and ignore the rest. If none are passed, it will use the default connection which is 'db'.

If extra options are passed, they will take precedence over the settings.ini file.

##### Parameters

$connection : mixed = null
$options : mixed = null
$pdo : mixed = null

##### Tags

throws
  Exception

##### Return values

Database

#### returningQuery()

Db.php : 1483

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