Omeka_Db

class Omeka_Db

Package: Db

Database manager object for Omeka

While mostly a wrapper for a Zend_Db_Adapter instance, this also providesshortcuts for retrieving table objects and table names for use in SQL.

property prefix

The prefix that every table in the omeka database will use.

property _adapter

The database adapter.

property _tables

All the tables that are currently managed by this database object.

property _logger

The logger to use for logging SQL queries. If not set, no logging will be done.

__construct(Zend_Db_Adapter_Abstract $adapter, string $prefix)
Parameters:
  • $adapter (Zend_Db_Adapter_Abstract) – A Zend Framework connection object.
  • $prefix (string) – The prefix for the database tables, if applicable.
__call(string $m, array $a)

Delegate to the database adapter.

Parameters:
  • $m (string) – Method name.
  • $a (array) – Method arguments.
Returns:

mixed

__get(string $name)

Magic getter is a synonym for Omeka_Db::getTableName().

Example: $db->Item is equivalent to $db->getTableName(‘Item’).

Parameters:
  • $name (string) – Property name; table model class name in this case.
Returns:

string|null

setLogger(Zend_Log $logger)

Set logger for SQL queries.

Parameters:
  • $logger (Zend_Log) –
getAdapter()

Retrieve the database adapter.

Returns:Zend_Db_Adapter_Abstract
getTableName($class)

Retrieve the name of the table (including the prefix).

Parameters:
  • $class (unknown) –
Returns:

string

hasPrefix()

Check whether the database tables have a prefix.

Returns:boolean
getTable(string $class)

Retrieve a table object corresponding to the model class.

Table classes can be extended by inheriting off of Omeka_Db_Table andthen calling your table Table_ModelName, e.g. Table_Item orTable_Collection. For backwards compatibility you may call your tableModelNameTable, i.e. ItemTable or CollectionTable. The latter namingpattern is deprecated.

This will cache every table object so that tables are not instantiatedmultiple times for complicated web requests.

Parameters:
  • $class (string) – Model class name.
Returns:

Omeka_Db_Table

setTable(string $alias, Omeka_Db_Table $table)

Cache a table object.

Prevents the creation of unnecessary instances.

Parameters:
insert(string $table, array $values = Array)

Every query ends up looking like: INSERT INTO table (field, field2, field3, ...) VALUES (?, ?, ?, ...) ON DUPLICATE KEY UPDATE field = ?, field2 = ?, ...

Note on portability: ON DUPLICATE KEY UPDATE is a MySQL extension.The advantage to using this is that it doesn’t care whether a row exists already.Basically it combines what would be insert() and update() methods in otherORMs into a single method

Parameters:
  • $table (string) – Table model class name.
  • $values (array) – Rows to insert (or update).
Returns:

integer The ID for the row that got inserted (or updated).

log(string|Zend_Db_Select $sql)

Log SQL query if logging is configured.

This logs the query before variable substitution from bind params.

Parameters:
  • $sql (string|Zend_Db_Select) –
queryBlock(string $sql, string $delimiter = ;)

Execute more than one SQL query at once.

Parameters:
  • $sql (string) – String containing SQL queries.
  • $delimiter (string) – Character that delimits each SQL query.
loadSqlFile(string $filePath)

Read the contents of an SQL file and execute all the queries therein.

In addition to reading the file, this will make substitutions based onspecific naming conventions. Currently makes the following substitutions:%PREFIX% will be replaced by the table prefix.

Parameters:
  • $filePath (string) – Path to the SQL file to load

Project Versions

Previous topic

Omeka_Captcha

Next topic

Omeka_Form

This Page