Database

Creating

Replace “booklink” with your project name wherever it is found. Use the case structure in the example.

<?php
 
  class BooklinkInstaller extends AkInstaller
  {
    function up_1(){
 
      $this->createTable('books', // The table name must be plural.
        'id,'.                    // This key must be in every table.
        'col_1 string(10),'.      // Columns have default characteristics.  
        'col_last'                // The last column does not end with a "."
      );
    }
 
    function down_1(){
      $this->dropTables('books');
    }
 }
 
?>

Simple enough. The column type options are:

Or any column type that is supported by the database you’re using, like varchar or smallint on MySQL. One warning though: do not use tinyint on MySQL because it will be typecasted as boolean.

See http://phplens.com/lens/adodb/docs-datadict.htm to customize column options.

Additional Database Functions

Tables

modifyTable($table_name, $column_options = null, $table_options = array()
No description

dropTable($table_name, $options = array())
No description

dropTables()
No description

getAvailableTables()
No description

tableExists($table_name)
No description

Columns

addColumn($table_name, $column_details)
Adds a new column to the table called $table_name

changeColumn($table_name, $column_details)
No description\

removeColumn($table_name, $column_name)
No description

renameColumn($table_name, $old_column_name, $new_column_name)
No description

getDefaultColumnAttributesRules()
Returns a key ⇒ value pair of regular expressions that will trigger methods to cast database columns to their respective default values or a replacement expression.

Indices

addIndex($table_name, $columns, $index_name = '')
No description

removeIndex($table_name, $columns_or_index_name)
No description

dropIndex($table_name, $columns_or_index_name)
No description

Sequences

createSequence($table_name)
No description

dropSequence($table_name)
No description

Transactions

transactionStart()
Transaction support for database operations

transactionComplete()
No description

transactionFail()
No description

transactionHasFailed()
No description

Miscellaneous

promptUserVar($message, $options = array()
Promts for a variable on console scripts

execute($sql)
No description

debug($toggle = null)
No description

Transactions

Transactions are enabled automatically for Installer objects. You can nest transactions within models. This transaction is nested. Only the outermost will be executed.

$UserInstalller->transactionStart();
$UserInstalller->addTable('id, name');
 
if(!isCompatible()){
    $User->transactionFail();
}
 
$User->transactionComplete();