DBUtil Class

package Fuel
category Core
author Dan Horrigan

 Methods

_init()

_init() 

Adds fields to a table a table.

add_fields(string $table, array $fields, string $db) : int

Will throw a Database_Exception if it cannot.

Parameters

$table

string

the table name

$fields

array

the new fields

$db

string

the database connection to use

Exceptions

\Fuel\Core\Fuel\Database_Exception

Returns

intthe number of affected

Adds a single foreign key to a table

add_foreign_key(string $table, array $foreign_key, string $db) : int

Parameters

$table

string

the table name

$foreign_key

array

a single foreign key

$db

string

the database connection to use

Returns

intnumber of affected rows

Analyzes a table.

analyze_table(string $table, string $db) : bool

Parameters

$table

string

the table name

$db

string

the database connection to use

Returns

boolwhether the table is OK

Checks a table.

check_table(string $table, string $db) : bool

Parameters

$table

string

the table name

$db

string

the database connection to use

Returns

boolwhether the table is OK

Creates a database.

create_database(string $database, string $charset, boolean $if_not_exists, string $db) : int

Will throw a Database_Exception if it cannot.

Parameters

$database

string

the database name

$charset

string

the character set

$if_not_exists

boolean

whether to add an IF NOT EXISTS statement.

$db

string

the database connection to use

Exceptions

\Fuel\Core\Fuel\Database_Exception

Returns

intthe number of affected rows

Creates an index on that table.

create_index(string $table, string $index_columns, string $index_name, string $index, string $db) : bool

access public
static
author Thomas Edwards

Parameters

$table

string

$index_columns

string

$index_name

string

$index

string

(should be 'unique', 'fulltext', 'spatial' or 'nonclustered')

$db

string

the database connection to use

Returns

bool

Creates a table.

create_table(string $table, array $fields, array $primary_keys, boolean $if_not_exists, string | boolean $engine, string $charset, array $foreign_keys, string $db) : int

Parameters

$table

string

the table name

$fields

array

the fields array

$primary_keys

array

an array of primary keys

$if_not_exists

boolean

whether to add an IF NOT EXISTS statement.

$engine

stringboolean

storage engine overwrite

$charset

string

default charset overwrite

$foreign_keys

array

an array of foreign keys

$db

string

the database connection to use

Exceptions

\Database_Exception

Returns

intnumber of affected rows.

Drops a database.

drop_database(string $database, string $db) : int

Will throw a Database_Exception if it cannot.

Parameters

$database

string

the database name

$db

string

the database connection to use

Exceptions

\Fuel\Core\Fuel\Database_Exception

Returns

intthe number of affected rows

Drops fields from a table a table.

drop_fields(string $table, string | array $fields, string $db) : int

Will throw a Database_Exception if it cannot.

Parameters

$table

string

the table name

$fields

stringarray

the fields

$db

string

the database connection to use

Exceptions

\Fuel\Core\Fuel\Database_Exception

Returns

intthe number of affected

Drops a foreign key from a table

drop_foreign_key(string $table, string $fk_name, string $db) : int

Parameters

$table

string

the table name

$fk_name

string

the foreign key name

$db

string

the database connection to use

Returns

intnumber of affected rows

Drop an index from a table.

drop_index(string $table, string $index_name, string $db) : bool

access public
static
author Thomas Edwards

Parameters

$table

string

$index_name

string

$db

string

the database connection to use

Returns

bool

Drops a table.

drop_table(string $table, string $db) : int

Will throw a Database_Exception if it cannot.

Parameters

$table

string

the table name

$db

string

the database connection to use

Exceptions

\Fuel\Core\Fuel\Database_Exception

Returns

intthe number of affected rows

Checks if given field(s) in a given table exists.

field_exists(string $table, string | array $columns, string $db) : bool

Parameters

$table

string

Table name

$columns

stringarray

columns to check

$db

string

the database connection to use

Exceptions

\Database_Exception

Returns

bool

Modifies fields in a table.

modify_fields(string $table, array $fields, string $db) : int

Will throw a Database_Exception if it cannot.

Parameters

$table

string

the table name

$fields

array

the modified fields

$db

string

the database connection to use

Exceptions

\Fuel\Core\Fuel\Database_Exception

Returns

intthe number of affected

Optimizes a table.

optimize_table(string $table, string $db) : bool

Parameters

$table

string

the table name

$db

string

the database connection to use

Returns

boolwhether the table has been optimized

Returns string of foreign keys

process_foreign_keys(array $foreign_keys, string $db) : string

Parameters

$foreign_keys

array

Array of foreign key rules

$db

string

the database connection to use

Exceptions

\Database_Exception

Returns

stringthe formatted foreign key string

Renames a table.

rename_table(string $table, string $new_table_name, string $db) : int

Will throw a Database_Exception if it cannot.

Parameters

$table

string

the old table name

$new_table_name

string

the new table name

$db

string

the database connection to use

Exceptions

\Database_Exception

Returns

intthe number of affected

Repairs a table.

repair_table(string $table, string $db) : bool

Parameters

$table

string

the table name

$db

string

the database connection to use

Returns

boolwhether the table has been repaired

Sets the database connection to use for following DBUtil calls.

set_connection(string $connection) 

Parameters

$connection

string

connection name, null for default

Exceptions

\FuelException

Checks if a given table exists.

table_exists(string $table, string $db) : bool

Parameters

$table

string

Table name

$db

string

the database connection to use

Exceptions

\Database_Exception

Returns

bool

Truncates a table.

truncate_table(string $table, string $db) : int

Parameters

$table

string

the table name

$db

string

the database connection to use

Exceptions

\Fuel\Core\Fuel\Database_Exception

Returns

intthe number of affected rows

alter_fields()

alter_fields($type, $table, $fields, $db) 

Parameters

$type

$table

$fields

$db

table_maintenance()

table_maintenance($operation, $table, $db) 

Parameters

$operation

$table

$db

 Properties

 

<p>the database connection (identifier)</p>

$connection : string