Overview

Namespaces

  • Charcoal
    • Loader
    • Model
      • Service
      • ServiceProvider
    • Source
      • Database
    • Validator

Classes

  • AbstractSource
  • DatabaseSource
  • DatabaseSourceConfig
  • Filter
  • Order
  • Pagination
  • SourceConfig

Interfaces

  • DatabaseSourceInterface
  • FilterInterface
  • OrderInterface
  • PaginationInterface
  • SourceInterface
  • StorableInterface

Traits

  • StorableTrait
  • Overview
  • Namespace
  • Class

Class DatabaseSource

Database Source, through PDO.

Charcoal\Source\AbstractSource implements Charcoal\Source\SourceInterface, Charcoal\Config\ConfigurableInterface, Psr\Log\LoggerAwareInterface uses Charcoal\Config\ConfigurableTrait (not available) Psr\Log\LoggerAwareTrait (not available)
Extended by Charcoal\Source\DatabaseSource implements Charcoal\Source\DatabaseSourceInterface
Namespace: Charcoal\Source
Located at Charcoal/Source/DatabaseSource.php
Methods summary
public
# __construct( array $data )

Parameters

$data
Class dependencies.

Overrides

Charcoal\Source\AbstractSource::__construct()
public Charcoal\Source\DatabaseSource
# setTable( string $table )

Set the database's table to use.

Set the database's table to use.

Parameters

$table
The source table.

Returns

Charcoal\Source\DatabaseSource
Chainable

Throws

InvalidArgumentException
If argument is not a string or alphanumeric/underscore.

Implementation of

Charcoal\Source\DatabaseSourceInterface::setTable()
public string
# table( )

Get the database's current table.

Get the database's current table.

Returns

string

Throws

Exception
If the table was not set.

Implementation of

Charcoal\Source\DatabaseSourceInterface::table()
public boolean
# createTable( )

Create a table from a model's metadata.

Create a table from a model's metadata.

Returns

boolean
Success / Failure

Implementation of

Charcoal\Source\DatabaseSourceInterface::createTable()
public boolean
# alterTable( )

Alter an existing table to match the model's metadata.

Alter an existing table to match the model's metadata.

Returns

boolean
Success / Failure

Implementation of

Charcoal\Source\DatabaseSourceInterface::alterTable()
public boolean
# tableExists( )

Returns

boolean

Implementation of

Charcoal\Source\DatabaseSourceInterface::tableExists()
public array
# tableStructure( )

Get the table columns information.

Get the table columns information.

Returns

array

Implementation of

Charcoal\Source\DatabaseSourceInterface::tableStructure()
public boolean
# tableIsEmpty( )

Check wether the source table is empty (true) or not (false)

Check wether the source table is empty (true) or not (false)

Returns

boolean

Implementation of

Charcoal\Source\DatabaseSourceInterface::tableIsEmpty()
public PDO
# db( )

Returns

PDO

Throws

Exception
If the database can not set.

Implementation of

Charcoal\Source\DatabaseSourceInterface::db()
public Charcoal\Source\StorableInterface
# loadItem( mixed $ident, Charcoal\Source\StorableInterface $item = null )

Parameters

$ident
Ident can be any scalar value.
$item
Optional item to load into.

Returns

Charcoal\Source\StorableInterface
public Charcoal\Source\StorableInterface
# loadItemFromKey( string $key, mixed $ident, Charcoal\Source\StorableInterface $item = null )

Load item from a custom column's name ($key)

Load item from a custom column's name ($key)

Parameters

$key
Column name.
$ident
Value of said column.
$item
Optional. Item (storable object) to load into.

Returns

Charcoal\Source\StorableInterface
Item

Throws

Exception
If the query fails.
public Charcoal\Source\StorableInterface
# loadItemFromQuery( string $query, array $binds = [], Charcoal\Source\StorableInterface $item = null )

Parameters

$query
The SQL query.
$binds
Optional. The query parameters.
$item
Optional. Item (storable object) to load into.

Returns

Charcoal\Source\StorableInterface
Item.

Throws

Exception
If there is a query error.
public array
# loadItems( Charcoal\Source\StorableInterface $item = null )

Parameters

$item
Optional item to use as model.

Returns

array

See

this->loadItemsFromQuery()
public array
# loadItemsFromQuery( string $q, array $binds = [], Charcoal\Source\StorableInterface $item = null )

Loads items to a list from a query Allows external use.

Loads items to a list from a query Allows external use.

Parameters

$q
The actual query.
$binds
This has to be done.
$item
Model Item.

Returns

array
Collection of Items | Model
public mixed
# saveItem( Charcoal\Source\StorableInterface $item )

Save an item (create a new row) in storage.

Save an item (create a new row) in storage.

Parameters

$item
The object to save.

Returns

mixed
The created item ID, or false in case of an error.

Throws

Exception
If a database error occurs.
public boolean
# updateItem( Charcoal\Source\StorableInterface $item, array $properties = null )

Update an item in storage.

Update an item in storage.

Parameters

$item
The object to update.
$properties
The list of properties to update, if not all.

Returns

boolean
Success / Failure
public boolean
# deleteItem( Charcoal\Source\StorableInterface $item = null )

Delete an item from storage

Delete an item from storage

Parameters

$item
Optional item to delete. If none, the current model object will be used.

Returns

boolean
Success / Failure

Throws

Exception
If the item does not have an ID.
public PDOStatement|false
# dbQuery( string $q, array $binds = [], array $binds_types = [] )

Execute a SQL query, with PDO, and returns the PDOStatement.

Execute a SQL query, with PDO, and returns the PDOStatement.

If the query fails, this method will return false.

Parameters

$q
The SQL query to executed.
$binds
Optional. Query parameter binds.
$binds_types
Optional. Types of parameter bindings.

Returns

PDOStatement|false
The PDOStatement, or false in case of error
public string
# sqlLoad( )

Returns

string

Throws

Exception
If the source does not have a table defined.
public string
# sqlLoadCount( )

Get a special SQL query for loading the count.

Get a special SQL query for loading the count.

Returns

string

Throws

Exception
If the source does not have a table defined.
public string
# sqlSelect( )

Returns

string
public string
# sqlFilters( )

Returns

string
public string
# sqlOrders( )

Returns

string
public string
# sqlPagination( )

Returns

string
protected Charcoal\Source\FilterInterface
# createFilter( )

Returns

Charcoal\Source\FilterInterface

Overrides

Charcoal\Source\AbstractSource::createFilter()
protected Charcoal\Source\OrderInterface
# createOrder( )

Returns

Charcoal\Source\OrderInterface

Overrides

Charcoal\Source\AbstractSource::createOrder()
protected Charcoal\Source\PaginationInterface
# createPagination( )

Returns

Charcoal\Source\PaginationInterface

Overrides

Charcoal\Source\AbstractSource::createPagination()
public Charcoal\Source\DatabaseSourceConfig
# createConfig( array $data = null )

ConfigurableTrait > createConfig()

ConfigurableTrait > createConfig()

Overrides the method defined in AbstractSource to returns a DatabaseSourceConfig object.

Parameters

$data
Optional.

Returns

Charcoal\Source\DatabaseSourceConfig

Overrides

Charcoal\Source\AbstractSource::createConfig()
Methods inherited from Charcoal\Source\AbstractSource
addFilter(), addOrder(), addProperty(), filters(), getter(), hasModel(), model(), numPerPage(), orders(), page(), pagination(), properties(), reset(), setData(), setFilters(), setModel(), setNumPerPage(), setOrders(), setPage(), setPagination(), setProperties(), setter()
Constants summary
string DEFAULT_DB_HOSTNAME
# 'localhost'
string DEFAULT_DB_TYPE
# 'mysql'
Properties inherited from Charcoal\Source\AbstractSource
$filters, $orders, $pagination
API documentation generated by ApiGen