/redaxo-core:redaxo-sql-patternsfrom redaxo-core
Provides patterns for database access in REDAXO using rex_sql: queries, prepared statements, transactions, and proper escaping. Useful when writing addon code that touches the database.
Ships in redaxo-core. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
rex_sql is REDAXO's database wrapper. It enforces prepared statements, namespaced table prefixes (rex_), and ships with a fluent builder for inserts/updates.
Always prefer rex_sql over raw PDO so you get the configured connection, prefix handling, and the addon's logging.
rex::getTable() helperREDAXO prefixes all tables (default rex_). Never hardcode the prefix – use rex::getTable('article') which returns rex_article. This keeps code portable across installations that use a different prefix (e.g. multi-instance setups).
$table = rex::getTable('article'); // → "rex_article"
$tableMyAddon = rex::getTable('my_addon_items');
setQuery with placeholdersAlways use parameter binding. Never concatenate user input into SQL.
$sql = rex_sql::factory();
$sql->setQuery(
'SELECT id, name FROM ' . rex::getTable('article') . '
WHERE clang_id = :clang AND status = :status
ORDER BY priority',
['clang' => rex_clang::getCurrentId(), 'status' => 1]
);
foreach ($sql as $row) {
echo (int) $row->getValue('id') . ': ' . rex_escape($row->getValue('name')) . "\n";
}
Iterating the $sql object yields one row at a time. Inside the loop, $row is the same object positioned on the current row.
To get all rows as an array (small result sets only):
$rows = $sql->getArray();
$sql = rex_sql::factory();
$sql->setQuery('SELECT COUNT(*) AS cnt FROM ' . rex::getTable('article') . ' WHERE status = ?', [1]);
$count = (int) $sql->getValue('cnt');
Positional placeholders (?) work too – pass values as a positional array.
$sql = rex_sql::factory();
$sql->setTable(rex::getTable('my_addon_log'));
$sql->setValue('user_id', rex::getUser()->getId());
$sql->setValue('action', 'login');
$sql->setDateTimeValue('created_at', time()); // formats to MySQL datetime
$sql->insert();
$newId = (int) $sql->getLastId();
$sql = rex_sql::factory();
$sql->setTable(rex::getTable('my_addon_log'));
$sql->setWhere(['id' => $logId]); // becomes "WHERE id = :id"
$sql->setValue('action', 'logout');
$sql->update();
For complex WHERE clauses, pass the SQL and parameters separately:
$sql->setWhere('user_id = :uid AND created_at > :since', [
'uid' => $userId,
'since' => '2026-01-01',
]);
$sql = rex_sql::factory();
$sql->setTable(rex::getTable('my_addon_log'));
$sql->setWhere(['id' => $logId]);
$sql->delete();
$sql = rex_sql::factory();
$sql->beginTransaction();
try {
// multiple statements...
$sql->commit();
} catch (Throwable $e) {
$sql->rollBack();
throw $e;
}
rex_sql::factory() returns a new rex_sql object on every call (own query, result and values), but all instances for the same DB share one PDO connection. A transaction therefore spans every rex_sql instance – no need to share an instance manually, and any second beginTransaction() call while the shared connection is already in a transaction (same instance or another) throws rex_sql_exception.
rex_sql_tableFor install.php / update.php in addons, use rex_sql_table instead of raw CREATE TABLE:
rex_sql_table::get(rex::getTable('my_addon_items'))
->ensurePrimaryIdColumn()
->ensureColumn(new rex_sql_column('title', 'varchar(255)', false, ''))
->ensureColumn(new rex_sql_column('body', 'text', true))
->ensureColumn(new rex_sql_column('created_at', 'datetime', false))
->ensureIndex(new rex_sql_index('idx_created', ['created_at']))
->ensure();
ensure() is idempotent – safe to run on every install/update. It compares the desired schema with the actual one and only applies the diff.
rex_ as the table prefix – use rex::getTable().mysqli_* or raw PDO directly – breaks with non-default DB configs.getValue() on a row object that hasn't been fetched (after exhausted iteration). Re-run the query or seek with $sql->next().getArray() consumes the result set – call it once, then operate on the array.DROP TABLE – rex_sql_table::get() caches the table definition per name, so exists() still returns true and ensure() tries to ALTER a table that is gone. Drop via rex_sql_table::get(rex::getTable('my_addon_items'))->drop(), which marks the cached instance as non-existing so ensure() creates the table again, or call rex_sql_table::clearInstance(rex::getTable('my_addon_items')) after an external DROP TABLE.getRow() – REDAXO opens PDO with ATTR_FETCH_TABLE_NAMES (core/lib/sql/sql.php), so the keys are rex_article.id, not id, and every $row['id'] lookup silently returns null. getValue('id') resolves the prefix itself and is unaffected; for plain keys use getArray(), which switches the attribute off for its own query. An object built from a getRow() array looks complete and has every property empty.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub friendsofredaxo/claude-marketplace --plugin redaxo-core11 skills in this plugin
/redaxo-addon-developmentBuilding and maintaining custom REDAXO addons – package.yml, boot.php, install/update/uninstall, lang files, fragments, backend pages, the assets pipeline (and the reinstall-to-sync rule), cache-busting on asset URLs, vendor dependencies, and the common-pitfalls checklist. Use when the user creates a new addon, edits package.yml, sets up backend pages, ships frontend assets from an addon, integrates Composer dependencies, or asks how to package functionality as a reusable addon./redaxo-api-functionsBuilding HTTP/AJAX endpoints in REDAXO using rex_api_function – the lib/ class location, naming convention, $published flag for frontend access, JSON responses, CORS for cross-domain widgets, and the rex-api-call URL. Use when the user adds an AJAX/HTTP endpoint to a custom addon, builds a JSON API for a frontend widget, or asks how to expose data via /index.php?rex-api-call=. Distinct from the FriendsOfRedaxo/api addon (covered by the redaxo-api-addon plugin)./redaxo-architectureREDAXO project structure, request lifecycle, and core classes. Use when the user works on a REDAXO codebase, mentions REDAXO directory layout, asks about rex_addon/rex_config/rex_path/rex_url/rex_clang/rex_request, or when files under redaxo/src/, redaxo/data/, or redaxo/cache/ appear in the conversation./redaxo-console-commandsBuilding CLI / diagnostic / maintenance commands for REDAXO addons using Symfony Console (rex_console_command). Covers the class location, naming convention, package.yml registration, and SymfonyStyle helpers. Use when the user adds a CLI tool to an addon, wants a cronjob entry point, builds a diagnostic command, or asks "how do I run X from the command line in REDAXO". Replaces the anti-pattern of writing standalone bootstrap scripts in bin/./redaxo-extension-pointsREDAXO Extension Points – the hook system for modifying core/addon behavior without patching files. Use when the user mentions rex_extension::register, hooks into events like ART_CONTENT / OUTPUT_FILTER / PACKAGES_INCLUDED, or wants to extend backend pages and content./redaxo-metainfo-fieldsDefining and managing REDAXO metainfo fields (cat_*, art_*, med_*) – the SELECT/RADIO/CHECKBOX `params` separator rules (| between options, : inside an option), the SQL-query escape hatch, the rex_metainfo_add_field idempotency caveat, and filtering categories by metainfo via rex_navigation::addFilter. Use when the user adds a metainfo field, sees broken/extra options in a metainfo dropdown, writes idempotent setup scripts that touch metainfo, or filters navigation by category metainfo.Other plugins' skills for the same job