The DB Adapter module provides classes for access to relational database via
PDO (PHP Data Object) drivers and classes. This
approach allows developers to use these classes to access a range of different database servers.

Parameters

Creates the info table that stores the version info of the current database.

createSchema()

createSchema($schema)

Takes a schema definition and creates it in the database.

Parameters

$schema

array

No description

createTable()

createTable($name, $columns)

Create a new table in the database.

Parameters

$name

string

No description

$columns

string

No description

delete()

delete($table, $criteria)

Parameters

$table

No description

$criteria

No description

deleteAll()

deleteAll($table)

Parameters

$table

No description

describeSequence()

describeSequence($name)

Parameters

$name

No description

describeTable()

describeTable($name, $sort = null)

Parameters

$name

No description

$sort

No description

dropColumn()

dropColumn($table, $column)

Parameters

$table

No description

$column

No description

dropConstraint()

dropConstraint($name, $table, $cascade = false)

Parameters

$name

No description

$table

No description

$cascade

No description

dropIndex()

dropIndex($name)

Parameters

$name

No description

dropTable()

dropTable($name, $cascade = false)

Parameters

$name

No description

$cascade

No description

errorCode()

errorCode()

errorInfo()

errorInfo()

exec()

exec($sql)

Parameters

$sql

No description

execCount()

execCount()

execute()

execute($name, $input_parameters)

Parameters

$name

No description

$input_parameters

No description

exists()

exists($table, $criteria = Array
(
)
)

Parameters

$table

No description

$criteria

No description

getAttribute()

getAttribute($option)

Parameters

$option

No description

getAvailableDrivers()

getAvailableDrivers()

getColumn()

getColumn($needle, $haystack, $key = 'name')

Parameters

$needle

No description

$haystack

No description

$key

No description

getColumnDiff()

getColumnDiff($new, $old)

Parameters

$new

No description

$old

No description

Static

getDefaultConfig()

getDefaultConfig($env = null)

Parameters

$env

No description

getDriver()

getDriver()

getLatestSchemaVersion()

getLatestSchemaVersion($with_file_obj = false)

Parameters

$with_file_obj

No description

getMigrationLog()

getMigrationLog()

Returns the migration log

Snapshots and migrations are complex processes where many things happen in a single execution. This means stuff
can go wrong and you will probably want to know what/why when they do.

When running \Hazaar\Adapter::snapshot() or \Hazaar\Adapter::migrate() a log of what has been done is stored internally
in an array of timestamped messages. You can use the \Hazaar\Adapter::getMigrationLog() method to retrieve this
log so that if anything goes wrong, you can see what and fix it/

getPreparedStatements()

getPreparedStatements()

getSchemaVersion()

getSchemaVersion()

getSchemaVersions()

getSchemaVersions($with_file_obj = false)

Parameters

$with_file_obj

No description

getTableDiffs()

getTableDiffs($new, $old)

Parameters

$new

No description

$old

No description

inTransaction()

inTransaction()

insert()

insert($table, $fields, $returning = null)

Parameters

$table

No description

$fields

No description

$returning

No description

isSchemaLatest()

isSchemaLatest()

lastInsertId()

lastInsertId()

listConstraints()

listConstraints($table = null, $type = null, $invert_type = false)

Parameters

$table

No description

$type

No description

$invert_type

No description

listForeignKeys()

listForeignKeys($table = null)

Parameters

$table

No description

listIndexes()

listIndexes($table = null)

Parameters

$table

No description

listPreparedStatements()

listPreparedStatements()

listPrimaryKeys()

listPrimaryKeys($table = null)

Parameters

$table

No description

listSequences()

listSequences()

listTables()

listTables()

List all tables currently in the connected database.

Tags

Since

2.0

loadDataFromFile()

loadDataFromFile($data_schema, $file, $child_element = null)

Parameters

$data_schema

No description

$file

No description

$child_element

No description

log()

log($msg)

Logs a message to the migration log.

Parameters

This method does some fancy database migration magic. It makes use of the ‘db’ subdirectory in the project directory
which should contain the schema.json file. This file is the current database schema definition.

A few things can occur here.

If the database schema does not exist, then a new schema will be created using the schema.json schema definition file.
This will create the database at the latest version of the schema.

If the database schema already exists, then the current version is checked against the version requested using the
$version parameter. If no version is requested ($version is NULL) then the latest version number is used.

If the version numbers are different, then a migration will be performed.

# If the requested version is greater than the current version, the migration mode will be ‘up’.

# If the requested version is less than the current version, the migration mode will be ‘down’.

All migration files between the two selected versions (current and requested) will be replayed using the migration mode.

This process can be used to bring a database schema up to the latest version using database migration files stored in the
db/migrate project subdirectory. These migration files are typically created using the \Hazaar\Adapter::snapshot() method
although they can be created manually. Take care when using manually created migration files.

The migration is performed in a database transaction (if the database supports it) so that if anything goes wrong there
is no damage to the database. If something goes wrong, errors will be availabl in the migration log accessible with
\Hazaar\Adapter::getMigrationLog(). Errors in the migration files can be fixed and the migration retried.

Parameters

$version

string

The database schema version to migrate to.

$force_data_sync

No description

$test

No description

Returns

boolean

Returns true on successful migration. False if no migration was neccessary. Throws an Exception on error.

prepare()

prepare($sql, $name = null)

Prepared statements

Parameters

$sql

No description

$name

No description

processDataObject()

processDataObject($info)

Parameters

$info

No description

query()

query($sql)

Parameters

$sql

No description

quote()

quote($string)

Parameters

$string

No description

renameTable()

renameTable($from_name, $to_name)

Parameters

$from_name

No description

$to_name

No description

replay()

replay($schema, $test = false)

Reply a database migration schema file

This should only be used internally by the migrate method to replay an individual schema migration file.

Parameters

$schema

array

The JSON decoded schema to replay.

$test

No description

rollBack()

rollBack()

setAttribute()

setAttribute()

Static

setDefaultConfig()

setDefaultConfig($config, $env = null)

Parameters

$config

No description

$env

No description

snapshot()

snapshot($comment = null, $test = false) : boolean

Snapshot the database schema and create a new schema version with migration replay files.

This method is used to create the database schema migration files. These files are used by the \Hazaar\Adapter::migrate()
method to bring a database up to a certain version. Using this method simplifies creating these migration files
and removes the need to create them manually when there are trivial changes.

When developing your project

Currently only the following changes are supported:

Table creation, removal and rename.

Column creation, removal and alteration.

Index creation and removal.

Table rename detection works by comparing new tables with removed tables for tables that have the same columns. Because
of this, rename detection will not work if columns are added or removed at the same time the table is renamed. If you want to
rename a table, make sure that this is the only operation being performed on the table for a single snapshot. Modifying other
tables will not affect this. If you want to rename a table AND change it’s column layout, make sure you do either the rename
or the modifications first, then snapshot, then do the other operation before snapshotting again.

Tags

Throws

\Exception

Parameters

$comment

string

A comment to add to the migration file.

$test

No description

Returns

boolean

True if the snapshot was successful. False if no changes were detected and nothing needed to be done.