Menu

## PormObject extends Database
in package
Uses TableLevelQueryTrait, AggregateTrait

PormObject.php : 30

This should not be worked with directly, use the Porm class instead.

### Table of Contents

#### Properties

$database : Core|null
  This is the Core object to use
$logging : bool
  This is the logging option to use
$options : array<string|int, mixed>
  This is the Medoo Object to pass along
$pormVersion : string
$using : string|null
  This is the Database connection to use, default is db
$alias : string|null
$allowFilterOnly : bool
$columns : string|array<string|int, mixed>|null
$pdo : PDO|null
  This is the PDO object you can pass along
$preventHas : bool
$preventRaw : true
$resultSet : mixed
$table : mixed
  The Database table to use
$where : array<string|int, mixed>

#### Methods

__construct() : mixed
__destruct() : mixed
asJson() : bool|string
asObject() : mixed
avg() : string|null
clean() : string
columns() : PormObject
  This defines the table column names to return from the Database
count() : int|null
createTable() : PDOStatement
deleteAll() : PDOStatement|null
  This deletes all items that match the where clause
deleteById() : PDOStatement|null
  This is under the hood similar to deleteOne but it is more explicit
drop() : PDOStatement|null
filter() : Builder
  This switches the query to filter mode. It is useful for conditional querying.
first() : object|array<string|int, mixed>|null
  This grabs the first [n] items from the Database based on the pkField given
from() : Porm
  This sets the table to use
get() : object|array<string|int, mixed>|null
  Fetches a single item from the Database.
getDatabase() : Core|null
has() : bool
  This checks if the table has a record that matches the where clause
info() : array<string|int, mixed>
  Returns the details of the current db connection
inTransaction() : void
  Using transactions. This is a wrapper for the action method in the Core class.
join() : object|null
  Opens the portal to the joins builder. Once you call this, you can call the join methods
last() : object|array<string|int, mixed>|null
  Grab the last item from the Database based on the pkField clause
lastId() : string|null
  Returns the id of the last inserted row
logs() : mixed
max() : string|null
min() : string|null
pdo() : PDO
  Returns the underlying pdo object From this, you can do anything you want with the pdo object
query() : PDOStatement
  Gives you access to the underlying medoo object and pdo object
random() : array<string|int, mixed>|mixed|object
  Fetches random n items from the table, default to 1
raw() : Raw
rawQuery() : mixed
  This assists to perform raw sql queries
save() : object
  Saves and returns the saved item as an object
sum() : string|null
table() : Porm
  This is for running queries. Should be called first
update() : PDOStatement|null
use() : Database
  This is a static method to use a Database connection. It will return a new Database instance with the connection passed.
using() : static
  This sets the connection to the Database to use for the current query.
builder() : Core
_resolve() : void
  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.
checkFilterMode() : void
  This prevents the use of non-filtering methods in filter mode.
reboot() : Core
  This sets up the Database connection to use internally. It is called when the Porm class is being set up.

### Properties

#### $database

Database.php : 50

This is the Core object to use

`public Core|null $database = null`

#### $logging

Database.php : 56

This is the logging option to use

`public bool $logging = false`

#### $options

Database.php : 32

This is the Medoo Object to pass along

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

#### $pormVersion

PormObject.php : 32
`public static string $pormVersion = "1.0.7"`

#### $using

Database.php : 44

This is the Database connection to use, default is db

`public string|null $using = 'db'`

#### $alias

PormObject.php : 42
`private string|null $alias`

The alias to use, will defualt to the table name provided.

#### $allowFilterOnly

PormObject.php : 50
`private bool $allowFilterOnly = false`

Lock out the use of any other method other than filter

#### $columns

PormObject.php : 59
`private string|array<string|int, mixed>|null $columns = '*'`

The columns to select

#### $pdo

Database.php : 38

This is the PDO object you can pass along

`private PDO|null $pdo = null`

#### $preventHas

PormObject.php : 46
`private bool $preventHas = false`

Lock out the use of filter

#### $preventRaw

PormObject.php : 63
`private true $preventRaw = false`

Lock out the use of raw queries

#### $resultSet

PormObject.php : 54
`private mixed $resultSet`

The result set to call asObject and asJson on.

#### $table

PormObject.php : 38

The Database table to use

`private mixed $table`

#### $where

PormObject.php : 64
`private array<string|int, mixed> $where = []`

### Methods

#### __construct()

PormObject.php : 69
`public __construct(mixed $table[, string|null $alias = null ][, string|null $using = null ]) : mixed`

##### Parameters

$table : mixed
$alias : string|null = null
$using : string|null = null

#### __destruct()

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

#### asJson()

TableLevelQueryTrait.php : 146
`public asJson() : bool|string`

##### Tags

throws
  Exception

##### Return values

bool|string

#### asObject()

TableLevelQueryTrait.php : 156
`public asObject() : mixed`

##### Tags

throws
  Exception

#### avg()

AggregateTrait.php : 53
`public avg(string $column, array<string|int, mixed>|null $where) : string|null`

##### Parameters

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

##### Tags

see
  Core::avg()

##### Return values

string|null

#### clean()

Database.php : 162
`public clean(string $value) : string`

##### Parameters

$value : string

##### Tags

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

  for more information on quoting values

##### Return values

string

#### columns()

TableLevelQueryTrait.php : 262

This defines the table column names to return from the Database

`public columns([string|array<string|int, mixed> $columns = "*" ]) : PormObject`

If you're in join mode, then all ambigous columns should define the table as an alias

##### Parameters

$columns : string|array<string|int, mixed> = "*"

  The columns to select defaults to * for all.

##### Tags

throws
  Exception
example

        $res1 = Porm::from('users')->columns('first_name')->get(1); // fetches the first name of the user with id 1
        $res2 = Porm::from('users')->columns(['first_name', 'last_name'])->get(1); // fetches the first name and last name of the user with id 1
        $res3 = Porm::from('users')->columns(['first_name', 'last_name'])->filter(['last_name' => 'Pionia'])->all(); // fetches the first name and last name of all users with last name Pionia

      // In joins

       $res4 = Porm::from("users", "u")
      ->columns(["u.id", "role_name", "role.created_at"])
      ->join()->left("role", [u.role_id => id])
      ->all();

##### Return values

PormObject —

The current Porm object

#### count()

AggregateTrait.php : 27
`public count([string|null $column = null ][, array<string|int, mixed>|null $where = null ]) : int|null`

##### Parameters

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

##### Tags

see
  Core::count()

##### Return values

int|null

#### createTable()

Database.php : 127
`public createTable(string $table_name, array<string|int, mixed> $columns, array<string|int, mixed> $options) : PDOStatement`

##### Parameters

$table_name : string
$columns : array<string|int, mixed>
$options : array<string|int, mixed>

##### Tags

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

  for more information on the creation of tables

##### Return values

PDOStatement

#### deleteAll()

TableLevelQueryTrait.php : 314

This deletes all items that match the where clause

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

##### Parameters

$where : array<string|int, mixed>

##### Tags

throws
  Exception
example

       $res1 = Porm::from('users')->deleteAll(['name' => 'John']); // deletes all users with name John
       $res2 = Porm::from('users')->deleteAll(['last_name' => 'Pionia', 'first_name'=>'Framework']); // deletes all users with last name Pionia and first_name as Framework

##### Return values

PDOStatement|null

#### deleteById()

TableLevelQueryTrait.php : 347

This is under the hood similar to deleteOne but it is more explicit

`public deleteById(string|int $id[, string|null $idField = 'id' ]) : PDOStatement|null`

##### Parameters

$id : string|int
$idField : string|null = 'id'

##### Tags

throws
  Exception

##### Return values

PDOStatement|null

#### drop()

Database.php : 137
`public drop(string $table_name) : PDOStatement|null`

##### Parameters

$table_name : string

##### Tags

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

  for more information on the dropping of tables

##### Return values

PDOStatement|null

#### filter()

TableLevelQueryTrait.php : 230

This switches the query to filter mode. It is useful for conditional querying.

`public filter([array<string|int, mixed>|null $where = [] ]) : Builder`

##### Parameters

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

  The where clause to use

##### Tags

throws
  Exception
example

       $res1 = Porm::from('users')->filter(['id' => 1])->get(); // fetches a user with id 1
       $res2 = Porm::from('users')->filter(['last_name' => 'Pionia', 'first_name'=>'Framework'])->all(); // fetches all users with last name Pionia and first_name as Framework
       $res2 = Porm::from('users')->filter(['last_name' => 'Pionia'])->limit(1)->startAt(2); // fetches a user with last name Pionia and first_name as Framework

##### Return values

Builder

#### first()

TableLevelQueryTrait.php : 381

This grabs the first [n] items from the Database based on the pkField given

`public first([int|null $size = 1 ][, array<string|int, mixed>|null $where = [] ][, string $pkField = 'id' ]) : object|array<string|int, mixed>|null`

##### Parameters

$size : int|null = 1

  The number of items to fetch

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

  The where clause to use

$pkField : string = 'id'

  The primary key field to use

##### Tags

throws
  Exception

##### Return values

object|array<string|int, mixed>|null

#### from()

PormObject.php : 105

This sets the table to use

`public static from(string $table[, string|null $alias = null ][, string|null $using = null ]) : Porm`

##### Parameters

$table : string

  The table to use

$alias : string|null = null

  The alias to use

$using : string|null = null

  The connection to use

##### Tags

throws
  BaseDatabaseException
example

          Table::from('user') // notice this here
            ->get(['last_name' => 'Pionia']);

##### Return values

Porm

#### get()

TableLevelQueryTrait.php : 186

Fetches a single item from the Database.

`public get([int|array<string|int, mixed>|string|null $where = null ][, string|null $idField = 'id' ]) : object|array<string|int, mixed>|null`

If the where clause is not passed, it fetches the last item in the table. If the where clause is an integer, it fetches the item with the id. If the where clause is an array, it fetches the item that matches the where clause. If the where clause is null, it fetches the last item in the table.

##### Parameters

$where : int|array<string|int, mixed>|string|null = null
$idField : string|null = 'id'

  defaults to id, pass this if you want to use a different field as the id other than id

##### Tags

throws
  Exception
example

         $res1 = Porm::from('users')->get(1); // fetches a user with id 1
         $res2 = Porm::from('users')->get(['id' => 1]); // fetches a user with id 1
         $res3 = Porm::from('users')->get(['last_name' => 'Pionia', 'first_name'=>'Framework']); // fetches a user with last name Pionia and first_name as Framework
        $res4 = Porm::from('users')->get(); // fetches the latest user in the table

##### Return values

object|array<string|int, mixed>|null

#### getDatabase()

PormObject.php : 131
`public getDatabase() : Core|null`

##### Return values

Core|null

#### has()

TableLevelQueryTrait.php : 46

This checks if the table has a record that matches the where clause

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

##### Parameters

$where : string|array<string|int, mixed>|int|null
$pkField : string|null = 'id'

##### Tags

throws
  Exception
example

           $res1 = Porm::from('users')->has(1); // with integer where clause that defaults to id = 1
           $res2 = Porm::from('users')->has(['id' => 1]); // with array where clause

##### Return values

bool

#### info()

PormObject.php : 187

Returns the details of the current db connection

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

##### Return values

array<string|int, mixed>

#### inTransaction()

PormObject.php : 175

Using transactions. This is a wrapper for the action method in the Core class.

`public inTransaction(callable $callback) : void`

To access data outside the transaction, Create a result variable and refer to the transaction callback with the keyword `use`, and you can get data back after when you assign it from inside.

##### Parameters

$callback : callable

  The callback to run. It should return a void.

##### Tags

example

           $row = null;
           Table::from('qa_criteria')
                 ->inTransaction(function (Table $instance) use (&$row) {
                       $row = $instance->save([
                           'name' => 'Status 3',
                           'description' => 'Must be single 4',
                           'best_of_total' => 6,
                       ]);
                   });

           var_dump($row);

throws
  Exception

#### join()

TableLevelQueryTrait.php : 364

Opens the portal to the joins builder. Once you call this, you can call the join methods

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

##### Parameters

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

##### Tags

example

      $res4 = Porm::from("users", "u")
      ->columns(["u.id", "role_name", "role.created_at"])
      ->join()->left("role", [u.role_id => id])
      ->all();

##### Return values

object|null

#### last()

TableLevelQueryTrait.php : 407

Grab the last item from the Database based on the pkField clause

`public last([int|null $size = 1 ][, array<string|int, mixed>|null $where = [] ][, string $pkField = 'id' ]) : object|array<string|int, mixed>|null`

##### Parameters

$size : int|null = 1

  The number of items to fetch

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

  The where clause to use

$pkField : string = 'id'

  The primary key field to use

##### Tags

throws
  Exception

##### Return values

object|array<string|int, mixed>|null

#### lastId()

Database.php : 171

Returns the id of the last inserted row

`public lastId() : string|null`

##### Return values

string|null

#### logs()

PormObject.php : 86
`public logs() : mixed`

#### max()

AggregateTrait.php : 65
`public max(string $column, array<string|int, mixed>|null $where) : string|null`

##### Parameters

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

##### Tags

see
  Core::max()

##### Return values

string|null

#### min()

AggregateTrait.php : 77
`public min(string $column, array<string|int, mixed>|null $where) : string|null`

##### Parameters

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

##### Tags

see
  Core::min()

##### Return values

string|null

#### pdo()

Database.php : 185

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

Database.php : 152

Gives you access to the underlying medoo object and pdo object

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

##### Parameters

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

##### Tags

example

      $data = $Database->query("SELECT email FROM account")->fetchAll();
      var_dump($data);

##### Return values

PDOStatement

#### random()

TableLevelQueryTrait.php : 76

Fetches random n items from the table, default to 1

`public random([int|null $limit = 1 ][, array<string|int, mixed>|null $where = null ]) : array<string|int, mixed>|mixed|object`

##### Parameters

$limit : int|null = 1
$where : array<string|int, mixed>|null = null

##### Tags

example

          $res1 = Porm::from('users')->random(); // fetches a random user
          $res2 = Porm::from('users')->random(5); // fetches 5 random users
          $res3 = Porm::from('users')->random(5, ['last_name' => 'Pionia']); // fetches 5 random users with last name Pionia

throws
  Exception

##### Return values

array<string|int, mixed>|mixed|object

#### raw()

TableLevelQueryTrait.php : 212
`public raw(string $query, array<string|int, mixed> $params) : Raw`

##### Parameters

$query : string

  The query to run

$params : array<string|int, mixed>

  The parameters to pass prepare along with the query

##### Tags

throws
  Exception

  If we are in any other realm than RAW

##### Return values

Raw

#### rawQuery()

PormObject.php : 140

This assists to perform raw sql queries

`public static rawQuery(string $query[, array<string|int, mixed>|null $params = [] ][, string|null $using = 'db' ]) : mixed`

##### Parameters

$query : string
$params : array<string|int, mixed>|null = []
$using : string|null = 'db'

##### Tags

throws
  Exception

#### save()

TableLevelQueryTrait.php : 115

Saves and returns the saved item as an object

`public save(array<string|int, mixed> $data) : object`

##### Parameters

$data : array<string|int, mixed>

  The data to save. Must be an associative array

##### Tags

throws
  Exception
example

         $res = Porm::from('users')->save(['first_name' => 'John', 'last_name' => 'Doe']);
         echo $res->id;

##### Return values

object —

The saved object

#### sum()

AggregateTrait.php : 41
`public sum(string $column, array<string|int, mixed>|null $where) : string|null`

##### Parameters

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

##### Tags

see
  Core::sum()

##### Return values

string|null

#### table()

PormObject.php : 125

This is for running queries. Should be called first

`public static table(string $table[, string|null $alias = null ][, string|null $using = null ]) : Porm`

##### Parameters

$table : string
$alias : string|null = null
$using : string|null = null

##### Tags

throws
  BaseDatabaseException
since

  v1.0.2 You can this method instead of from(), but this is more readable

see
  from()

##### Return values

Porm

#### update()

TableLevelQueryTrait.php : 132
`public update(array<string|int, mixed> $data, array<string|int, mixed>|int|string $where[, string|null $idField = 'id' ]) : PDOStatement|null`

##### Parameters

$data : array<string|int, mixed>
$where : array<string|int, mixed>|int|string
$idField : string|null = 'id'

##### Tags

throws
  Exception

##### Return values

PDOStatement|null

#### use()

Database.php : 196

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

#### using()

TableLevelQueryTrait.php : 279

This sets the connection to the Database to use for the current query.

`public using([string $connection = 'db' ]) : static`

It can be used to switch between Database connections.

##### Parameters

$connection : string = 'db'

  The connection to use, defaults to 'db'

##### Tags

throws
  Exception

##### Return values

static

#### builder()

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

##### Parameters

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

##### Tags

throws
  Exception

##### Return values

Core

#### _resolve()

Database.php : 78

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 _resolve([mixed $connection = null ][, mixed $options = null ][, mixed $pdo = null ]) : void`

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

#### checkFilterMode()

TableLevelQueryTrait.php : 333

This prevents the use of non-filtering methods in filter mode.

`private checkFilterMode([string $msg = 'Query is in filter mode, you cannot use this method in filter mode' ]) : void`

Case here is like calling get() on join() yet join() return no resultset yet.

##### Parameters

$msg : string = 'Query is in filter mode, you cannot use this method in filter mode'

  The message to throw

  This is primarily used internally for the purpose.

      $this->checkFilterMode("You cannot delete at this point in the query, check the usage of the `delete()` method in the query builder for ".$this->table);

##### Tags

throws
  Exception

#### reboot()

TableLevelQueryTrait.php : 292

This sets up the Database connection to use internally. It is called when the Porm class is being set up.

`private reboot() : Core`

##### Tags

throws
  Exception

##### Return values

Core

## Search results