Differences
This shows you the differences between the selected revision and the current version of the page.
punbb13:database_helpers 2010/04/12 06:45 | punbb13:database_helpers 2020/02/06 11:04 current | ||
---|---|---|---|
Line 23: | Line 23: | ||
Let's discuss how to use the query builder. | Let's discuss how to use the query builder. | ||
- | ===== Data Manipulation in query builder ====== | + | ===== Query Builder: Data Manipulation ====== |
- | + | ||
- | First consider the DML (Data Manipulation Language) part of the PunBB database layer class. | + | |
==== SELECT ==== | ==== SELECT ==== | ||
Line 136: | Line 134: | ||
$forum_db->query_build($query) or error(__FILE__, __LINE__);</code> | $forum_db->query_build($query) or error(__FILE__, __LINE__);</code> | ||
- | ===== Data Definition in query builder ====== | + | ===== Data Definition ====== |
Now let's consider the DDL (Data Definition Language) part of the PunBB database layer class. | Now let's consider the DDL (Data Definition Language) part of the PunBB database layer class. | ||
Line 216: | Line 214: | ||
<code php>function drop_field($table_name, $field_name, $no_prefix = false)</code> | <code php>function drop_field($table_name, $field_name, $no_prefix = false)</code> | ||
- | Deletes the ''$field_name'' field from the ''$table_name'' table. | + | Removes the ''$field_name'' field from the ''$table_name'' table. |
- | Here are some examples of the fields manipulation. | + | Here are examples of the fields manipulation. |
- | <code php>// Taken from db_update.php | + | <code php>// Taken from admin/db_update.php |
$forum_db->alter_field('posts', 'poster_ip', 'VARCHAR(39)', true); | $forum_db->alter_field('posts', 'poster_ip', 'VARCHAR(39)', true); | ||
$forum_db->alter_field('users', 'registration_ip', 'VARCHAR(39)', false, '0.0.0.0');</code> | $forum_db->alter_field('users', 'registration_ip', 'VARCHAR(39)', false, '0.0.0.0');</code> | ||
Line 233: | Line 231: | ||
==== Indexes ==== | ==== Indexes ==== | ||
- | FIXME | ||
+ | <code php>function index_exists($table_name, $index_name, $no_prefix = false)</code> | ||
+ | |||
+ | Checks if the index ''$index_name'' is present in the table ''$table_name''. | ||
+ | |||
+ | <code php>function add_index($table_name, $index_name, $index_fields, $unique = false, $no_prefix = false)</code> | ||
+ | |||
+ | Adds an index to the ''$table_name'' table. ''$index_fields'' is the array of fields to be added to the index. | ||
+ | |||
+ | <code php>function drop_index($table_name, $index_name, $no_prefix = false)</code> | ||
+ | |||
+ | Removes the ''$index_name'' index from the ''$table_name'' table. | ||
+ | |||
+ | Here are examples of the indexes manipulation. | ||
+ | |||
+ | <code php>// Taken from admin/db_update.php | ||
+ | if (!$forum_db->index_exists('online', 'user_id_ident_idx')) | ||
+ | { | ||
+ | ... | ||
+ | $forum_db->add_index('online', 'user_id_ident_idx', array('user_id', 'ident'), true); | ||
+ | ... | ||
+ | } | ||
+ | |||
+ | $forum_db->drop_index('online', 'user_id_idx');</code> |