用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-php --skill php-database命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
PHP API development mastery - REST, GraphQL, JWT/OAuth, OpenAPI documentation
Modern PHP programming skill - master PHP 8.x syntax, OOP, type system, and Composer
Laravel framework mastery - Eloquent, Blade, APIs, queues, and Laravel 11.x ecosystem
| name | php-database |
| version | 2.0.0 |
| description | PHP database mastery - PDO, Eloquent, Doctrine, query optimization, and migrations |
| sasmp_version | 1.3.0 |
| bonded_agent | 05-php-database |
| bond_type | PRIMARY_BOND |
| atomic | true |
| category | data |
Atomic skill for mastering database operations in PHP
Comprehensive skill for PHP database interactions covering PDO, ORM patterns, query optimization, schema design, and migrations.
interface SkillParams {
topic:
| "pdo" // Native PHP database
| "eloquent" // Laravel ORM
| "doctrine" // Symfony ORM
| "optimization" // Query tuning, indexing
| "migrations" // Schema versioning
| "transactions"; // ACID, locking
level: "beginner" | "intermediate" | "advanced";
database?: "mysql" | "postgresql" | "sqlite";
orm?: "eloquent" | "doctrine" | "none";
}
validation:
topic:
required: true
allowed: [pdo, eloquent, doctrine, optimization, migrations, transactions]
level:
required: true
database:
default: "mysql"
beginner:
- Connection and DSN
- Prepared statements
- Fetching results
intermediate:
- Error handling modes
- Transactions basics
- Named placeholders
advanced:
- Connection pooling
- Stored procedures
- Batch operations
beginner:
- Basic indexing
- EXPLAIN basics
- WHERE clause optimization
intermediate:
- Composite indexes
- Join optimization
- Query profiling
advanced:
- Execution plan analysis
- Partitioning
- Query caching
beginner:
- Model basics
- CRUD operations
- Simple relationships
intermediate:
- Eager loading (N+1 prevention)
- Query scopes
- Lifecycle hooks
advanced:
- Custom repositories
- Result caching
- Batch processing
errors:
CONNECTION_ERROR:
code: "DB_001"
recovery: "Check connection string, retry with backoff"
DEADLOCK_ERROR:
code: "DB_002"
recovery: "Retry transaction with exponential backoff"
QUERY_ERROR:
code: "DB_003"
recovery: "Check SQL syntax, validate parameters"
retry:
max_attempts: 3
backoff:
type: exponential
initial_delay_ms: 100
max_delay_ms: 2000
retryable: [CONNECTION_ERROR, DEADLOCK_ERROR]
<?php
declare(strict_types=1);
final class Database
{
private \PDO $pdo;
public function __construct(string $dsn, string $user, string $pass)
{
$this->pdo = new \PDO($dsn, $user, $pass, [
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::ATTR_EMULATE_PREPARES => false,
]);
}
public function findById(int $id): ?array
{
$stmt = $this->pdo->prepare('SELECT * FROM users WHERE id = :id');
$stmt->execute(['id' => $id]);
return $stmt->fetch() ?: null;
}
{
= ->pdo->(
);
->();
() ->pdo->();
}
}
<?php
declare(strict_types=1);
final class TransactionService
{
public function executeWithRetry(
\PDO $pdo,
callable $operation,
int $maxRetries = 3
): mixed {
$attempt = 0;
while (true) {
try {
$pdo->beginTransaction();
$result = $operation($pdo);
$pdo->commit();
return $result;
} catch (\PDOException $e) {
$pdo->rollBack();
if (++$attempt >= $maxRetries || !$this->isRetryable($e)) {
throw $e;
}
usleep(100000 * pow(2, $attempt)); // Exponential backoff
}
}
}
{
(->(), );
}
}
<?php
// BAD: N+1 problem
$posts = Post::all();
foreach ($posts as $post) {
echo $post->author->name; // Query per post!
}
// GOOD: Eager loading
$posts = Post::with('author')->get();
foreach ($posts as $post) {
echo $post->author->name; // No extra queries
}
// BETTER: Select specific columns
$posts = Post::with(['author:id,name'])->get(['id', 'title', 'author_id']);
-- Before: Full table scan
SELECT * FROM orders WHERE status = 'pending';
-- Step 1: Add index
CREATE INDEX idx_orders_status ON orders(status);
-- Step 2: Analyze with EXPLAIN
EXPLAIN SELECT * FROM orders WHERE status = 'pending';
-- Result: Index scan instead of full table scan
| Problem | Detection | Solution |
|---|---|---|
| N+1 queries | Debugbar shows 100+ queries | Use eager loading with() |
| Slow queries | Query > 1 second | Add indexes, run EXPLAIN |
| Deadlocks | "Deadlock found" error | Implement retry logic |
| Memory exhaustion | Memory limit error | Use chunk() or cursor() |
<?php
// BAD: Loads all into memory
$users = User::all();
// GOOD: Chunk processing
User::chunk(1000, function ($users) {
foreach ($users as $user) {
// Process
}
});
// BETTER: Cursor for minimal memory
foreach (User::cursor() as $user) {
// Process one at a time
}
| Metric | Target |
|---|---|
| Prepared statements | 100% |
| N+1 prevention | 100% |
| Index recommendations | ≥95% |
| Transaction safety | 100% |
Skill("php-database", {topic: "optimization", level: "advanced"})
基于 SOC 职业分类