class-database-export-engine.php
3 months ago
class-database-export-processor.php
3 months ago
class-database-export-repository.php
3 months ago
interface-database-export-repository.php
3 months ago
interface-database-export-repository.php
94 lines
| 1 | <?php |
| 2 | |
| 3 | namespace BMI\Plugin\Database\Export; |
| 4 | |
| 5 | /** |
| 6 | * Interface DatabaseExportRepositoryInterface |
| 7 | * |
| 8 | * Defines the contract for database interactions used in database export operations. |
| 9 | * Implementations can use MySQLi or WordPress $wpdb with consistent behavior. |
| 10 | */ |
| 11 | interface DatabaseExportRepositoryInterface |
| 12 | { |
| 13 | /** |
| 14 | * Escapes a string for safe use in SQL queries. |
| 15 | * |
| 16 | * @param string $string The string to escape. |
| 17 | * @return string The escaped string. |
| 18 | */ |
| 19 | public function escape($string); |
| 20 | |
| 21 | /** |
| 22 | * Escapes a SQL identifier (table/column name) with backticks. |
| 23 | * |
| 24 | * @param string $identifier The identifier to escape. |
| 25 | * @return string The escaped identifier wrapped in backticks. |
| 26 | */ |
| 27 | public function escapeIdentifier($identifier); |
| 28 | |
| 29 | /** |
| 30 | * Retrieves the last error message from the database. |
| 31 | * |
| 32 | * @return string|null The last error message, or null if no error. |
| 33 | */ |
| 34 | public function getLastError(); |
| 35 | |
| 36 | /** |
| 37 | * Retrieves all table names from the current database. |
| 38 | * |
| 39 | * @return array List of table names. |
| 40 | */ |
| 41 | public function getTableNames(); |
| 42 | |
| 43 | /** |
| 44 | * Retrieves table size and row count information. |
| 45 | * |
| 46 | * @param string $table The table name. |
| 47 | * @param string $dbName The database name. |
| 48 | * @return array{size: float, rows: int}|null Table info or null on failure. |
| 49 | */ |
| 50 | public function getTableInfo($table, $dbName); |
| 51 | |
| 52 | /** |
| 53 | * Retrieves column information for a table. |
| 54 | * |
| 55 | * @param string $table The table name. |
| 56 | * @return array{primary_key: string|false, auto_increment_primary_key: string|false, columns: array} |
| 57 | */ |
| 58 | public function getTableColumnsInfo($table); |
| 59 | |
| 60 | /** |
| 61 | * Gets the CREATE TABLE statement for a table. |
| 62 | * |
| 63 | * @param string $table The table name. |
| 64 | * @return string|null The CREATE TABLE SQL or null on failure. |
| 65 | */ |
| 66 | public function getCreateTableStatement($table); |
| 67 | |
| 68 | /** |
| 69 | * Fetches rows from the database as numerically-indexed arrays. |
| 70 | * |
| 71 | * @param string $sql The SQL query to execute. |
| 72 | * @param bool $useUnbuffered Whether to use unbuffered query mode. |
| 73 | * @return \Generator Yields rows as numerically-indexed arrays. |
| 74 | */ |
| 75 | public function fetchRows($sql, $useUnbuffered = false); |
| 76 | |
| 77 | /** |
| 78 | * Gets the row count for a specific query/table. |
| 79 | * |
| 80 | * @param string $table The table name. |
| 81 | * @param string $whereClause Optional WHERE clause. |
| 82 | * @return int The row count. |
| 83 | */ |
| 84 | public function getRowCount($table, $whereClause = ''); |
| 85 | |
| 86 | /** |
| 87 | * Executes a raw SQL query (e.g., SET foreign_key_checks). |
| 88 | * |
| 89 | * @param string $sql The SQL to execute. |
| 90 | * @return bool True on success, false on failure. |
| 91 | */ |
| 92 | public function execute($sql); |
| 93 | } |
| 94 |