| Next revision | Previous revision |
| scriptlog:lib:core:db [2026/09/26 09:09] – admin admin | scriptlog:lib:core:db [2026/09/26 09:34] (current) – admin admin |
|---|
| ======= Docblock Metadata ======= | ======= Docblock Metadata ======= |
| |
| ^ Tag ^ Value ^ | ^ Tag ^ Value ^ |
| | ''@category'' | Core Class | | | ''@category'' | Core Class | |
| | ''@author'' | M.Noermoehammad | | | ''@author'' | M.Noermoehammad | |
| | ''@license'' | MIT | | | ''@license'' | MIT | |
| | ''@version'' | 1.0 | | | ''@version'' | 1.0 | |
| | ''@since'' | Since Release 1.0 | | | ''@since'' | Since Release 1.0 | |
| | ''@see'' | DbInterface | | | ''@see'' | DbInterface | |
| |
| ======= Inheritance ======= | ======= Inheritance ======= |
| |
| ^ Relation ^ Type ^ Meaning ^ | ^ Relation ^ Type ^ Meaning ^ |
| | implements | [[scriptlog:lib:core:dbinterface|''DbInterface'']] | contract | | | implements | [[scriptlog:lib:core:dbinterface|''DbInterface'']] | contract | |
| |
| ======= Constants (1) ======= | ======= Constants (1) ======= |
| |
| ^ Visibility ^ Name ^ Value ^ Line ^ | ^ Visibility ^ Name ^ Value ^ Line ^ |
| | ''private'' | ''STATEMENT_CACHE_MAX'' | ''64;'' | 88 | | | ''private'' | ''STATEMENT_CACHE_MAX'' | ''64;'' | 88 | |
| |
| ======= Properties (0) ======= | ======= Properties (5) ======= |
| |
| //None declared.// | ^ Visibility ^ Type ^ Name ^ Default ^ Line ^ |
| | | ''private'' | ''?string'' | ''$caPath'' | ''null'' | 36 | |
| | | ''private'' | ''string'' | ''$tablePrefix'' | '''''' | 43 | |
| | | ''private'' | ''array'' | ''$knownTables'' | ''[ 'tbl_users', 'tbl_user_token', 'tbl_login_attempt', 'tbl_…'' | 50 | |
| | | ''private'' | ''array'' | ''$statementCache'' | ''[]'' | 81 | |
| | | ''private'' | ''?string'' | ''$tablePrefixPattern'' | ''null'' | 95 | |
| |
| ======= Methods (21) ======= | ======= Methods (21) ======= |
| |
| ^ Visibility ^ Method ^ Summary ^ Line ^ | ^ Visibility ^ Method ^ Summary ^ Line ^ |
| | public | ''__construct()'' | Constructor - Initializes the database connection if config is provided | 103 | | | public | ''__construct()'' | Constructor - Initializes the database connection if config is provided | 103 | |
| | public | ''setTablePrefix()'' | Set table prefix | 115 | | | public | ''setTablePrefix()'' | Set table prefix | 115 | |
| | public | ''getTablePrefix()'' | Get table prefix | 125 | | | public | ''getTablePrefix()'' | Get table prefix | 125 | |
| | public | ''setDbConnection()'' | Establishes a database connection using PDO | 139 | | | public | ''setDbConnection()'' | Establishes a database connection using PDO | 139 | |
| | public | ''isConnected()'' | Checks if database connection is active | 170 | | | public | ''isConnected()'' | Checks if database connection is active | 170 | |
| | public | ''closeDbConnection()'' | Closes the database connection | 180 | | | public | ''closeDbConnection()'' | Closes the database connection | 180 | |
| | private | ''ensureConnection()'' | Ensures database connection is established before operations | 192 | | | private | ''ensureConnection()'' | Ensures database connection is established before operations | 192 | |
| | public | ''dbQuery()'' | Executes a database query and returns the statement | 207 | | | public | ''dbQuery()'' | Executes a database query and returns the statement | 207 | |
| | public | ''dbSelect()'' | Executes a SELECT query and returns results | 226 | | | public | ''dbSelect()'' | Executes a SELECT query and returns results | 226 | |
| | private | ''prepareCached()'' | Prepare a SQL statement with table prefix applied, reusing already | 251 | | | private | ''prepareCached()'' | Prepare a SQL statement with table prefix applied, reusing already | 251 | |
| | public | ''clearStatementCache()'' | Forget all cached prepared statements. | 271 | | | public | ''clearStatementCache()'' | Forget all cached prepared statements. | 271 | |
| | public | ''dbInsert()'' | Inserts a new record into the specified table | 285 | | | public | ''dbInsert()'' | Inserts a new record into the specified table | 285 | |
| | public | ''dbLastInsertId()'' | Returns the last inserted ID | 316 | | | public | ''dbLastInsertId()'' | Returns the last inserted ID | 316 | |
| | public | ''dbUpdate()'' | Updates records in the specified table | 332 | | | public | ''dbUpdate()'' | Updates records in the specified table | 332 | |
| | public | ''dbReplace()'' | Performs an INSERT or UPDATE (upsert) operation | 366 | | | public | ''dbReplace()'' | Performs an INSERT or UPDATE (upsert) operation | 366 | |
| | public | ''dbDelete()'' | Deletes records from the specified table | 405 | | | public | ''dbDelete()'' | Deletes records from the specified table | 405 | |
| | public | ''dbTransaction()'' | Begins a transaction | 436 | | | public | ''dbTransaction()'' | Begins a transaction | 436 | |
| | public | ''dbCommit()'' | Commits a transaction | 448 | | | public | ''dbCommit()'' | Commits a transaction | 448 | |
| | public | ''dbRollBack()'' | Rolls back a transaction | 460 | | | public | ''dbRollBack()'' | Rolls back a transaction | 460 | |
| | public | ''prepare()'' | Prepare a SQL statement with table prefix applied. | 477 | | | public | ''prepare()'' | Prepare a SQL statement with table prefix applied. | 477 | |
| | private | ''applyTablePrefix()'' | Apply table prefix to SQL query | 490 | | | private | ''applyTablePrefix()'' | Apply table prefix to SQL query | 490 | |
| |
| |
| Constructor - Initializes the database connection if config is provided | Constructor - Initializes the database connection if config is provided |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$config'' | ''array'' | ''[]'' | Database configuration [DSN, username, password] | | | ''$config'' | ''array'' | ''[]'' | Database configuration [DSN, username, password] | |
| | ''$options'' | ''array'' | ''[]'' | Additional PDO connection options | | | ''$options'' | ''array'' | ''[]'' | Additional PDO connection options | |
| |
| |
| Set table prefix | Set table prefix |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$prefix'' | ''string'' | //required// | //none// | | | ''$prefix'' | ''string'' | //required// | //none// | |
| |
| **Returns:** ''void'' | **Returns:** ''void'' |
| Establishes a database connection using PDO | Establishes a database connection using PDO |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$config'' | ''array'' | ''[]'' | Database configuration [DSN, username, password] | | | ''$config'' | ''array'' | ''[]'' | Database configuration [DSN, username, password] | |
| | ''$options'' | ''array'' | ''[]'' | Additional PDO connection options | | | ''$options'' | ''array'' | ''[]'' | Additional PDO connection options | |
| |
| **Returns:** ''void'' — void | **Returns:** ''void'' — void |
| Executes a database query and returns the statement | Executes a database query and returns the statement |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$sql'' | ''string'' | //required// | SQL query to execute | | | ''$sql'' | ''string'' | //required// | SQL query to execute | |
| | ''$args'' | ''array'' | ''[]'' | Parameters for prepared statement | | | ''$args'' | ''array'' | ''[]'' | Parameters for prepared statement | |
| |
| **Returns:** ''\PDOStatement'' — \PDOStatement Executed statement | **Returns:** ''\PDOStatement'' — \PDOStatement Executed statement |
| Executes a SELECT query and returns results | Executes a SELECT query and returns results |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$sql'' | ''string'' | //required// | SQL SELECT query | | | ''$sql'' | ''string'' | //required// | SQL SELECT query | |
| | ''$parameters'' | ''array'' | ''[]'' | Query parameters | | | ''$parameters'' | ''array'' | ''[]'' | Query parameters | |
| | ''$fetchMode'' | ''int'' | ''\PDO::FETCH_OBJ'' | PDO fetch mode (default: PDO::FETCH_OBJ) | | | ''$fetchMode'' | ''int'' | ''\PDO::FETCH_OBJ'' | PDO fetch mode (default: PDO::FETCH_OBJ) | |
| | ''$class'' | ''string'' | '''''' | Class name for PDO::FETCH_CLASS mode | | | ''$class'' | ''string'' | '''''' | Class name for PDO::FETCH_CLASS mode | |
| |
| **Returns:** ''array'' — array Fetched results | **Returns:** ''array'' — array Fetched results |
| reset so the request continues with fresh prepares. | reset so the request continues with fresh prepares. |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$sql'' | ''string'' | //required// | Fully-prefixed SQL query | | | ''$sql'' | ''string'' | //required// | Fully-prefixed SQL query | |
| |
| **Returns:** ''\PDOStatement'' — \PDOStatement | **Returns:** ''\PDOStatement'' — \PDOStatement |
| Inserts a new record into the specified table | Inserts a new record into the specified table |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$tablename'' | ''string'' | //required// | Name of the table | | | ''$tablename'' | ''string'' | //required// | Name of the table | |
| | ''$params'' | ''array'' | //required// | Associative array of column => value pairs | | | ''$params'' | ''array'' | //required// | Associative array of column => value pairs | |
| |
| **Returns:** ''bool'' — bool True on success, false on failure | **Returns:** ''bool'' — bool True on success, false on failure |
| Updates records in the specified table | Updates records in the specified table |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$tablename'' | ''string'' | //required// | Name of the table | | | ''$tablename'' | ''string'' | //required// | Name of the table | |
| | ''$params'' | ''array'' | //required// | Associative array of column => value pairs to update | | | ''$params'' | ''array'' | //required// | Associative array of column => value pairs to update | |
| | ''$where'' | ''array'' | //required// | Associative array of conditions for WHERE clause | | | ''$where'' | ''array'' | //required// | Associative array of conditions for WHERE clause | |
| |
| **Returns:** ''int'' — int Number of affected rows | **Returns:** ''int'' — int Number of affected rows |
| Inserts a new record or updates existing one if duplicate key exists | Inserts a new record or updates existing one if duplicate key exists |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$tablename'' | ''string'' | //required// | Name of the table | | | ''$tablename'' | ''string'' | //required// | Name of the table | |
| | ''$params'' | ''array'' | //required// | Associative array of column => value pairs for insert | | | ''$params'' | ''array'' | //required// | Associative array of column => value pairs for insert | |
| | ''$updateParams'' | ''array'' | //required// | Associative array of column => value pairs for update | | | ''$updateParams'' | ''array'' | //required// | Associative array of column => value pairs for update | |
| |
| **Returns:** ''bool'' — bool True on success, false on failure | **Returns:** ''bool'' — bool True on success, false on failure |
| Deletes records from the specified table | Deletes records from the specified table |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$tablename'' | ''string'' | //required// | Name of the table | | | ''$tablename'' | ''string'' | //required// | Name of the table | |
| | ''$where'' | ''array'' | //required// | Associative array of conditions for WHERE clause | | | ''$where'' | ''array'' | //required// | Associative array of conditions for WHERE clause | |
| | ''$limit'' | ''?int'' | ''null'' | Optional maximum number of rows to delete | | | ''$limit'' | ''?int'' | ''null'' | Optional maximum number of rows to delete | |
| |
| **Returns:** ''int'' — int Number of affected rows | **Returns:** ''int'' — int Number of affected rows |
| $dbc->prepare() directly to work correctly with prefixed table names. | $dbc->prepare() directly to work correctly with prefixed table names. |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$sql'' | ''string'' | //required// | SQL query (may contain unprefixed tbl_ names) | | | ''$sql'' | ''string'' | //required// | SQL query (may contain unprefixed tbl_ names) | |
| | ''$driverOptions'' | ''array'' | ''[]'' | Optional PDO driver options | | | ''$driverOptions'' | ''array'' | ''[]'' | Optional PDO driver options | |
| |
| **Returns:** ''(none declared)'' — \PDOStatement|false | **Returns:** ''(none declared)'' — \PDOStatement|false |
| Apply table prefix to SQL query | Apply table prefix to SQL query |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$sql'' | ''string'' | //required// | //none// | | | ''$sql'' | ''string'' | //required// | //none// | |
| |
| **Returns:** ''string'' — string | **Returns:** ''string'' — string |