rockschtar / wordpress-database-fluent
Fluent WordPress database ($wpdb) wrapper
Installs: 4 227
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=8.2
Requires (Dev)
- squizlabs/php_codesniffer: ^3.9.1
This package is auto-updated.
Last update: 2024-11-28 12:53:00 UTC
README
Fluent WordPress database ($wpdb) wrapper
Installation
You can install the package via composer:
composer require rockschtar/wordpress-database-fluent
Usage Examples
For more information about WordPress Database wpdb
visit https://developer.wordpress.org/reference/classes/wpdb/
$wpdb->insert
Insert a row into a table.
WPDB::insert() ->table('wp_my_table') ->data(['column1' => 'hello', 'column2' => 'world', 'column3' => 1]) ->format(['%s', '%s', '%d']) ->execute();
$wpdb->update
Update a row in the table
WPDB::update() ->table('wp_my_table') ->data(['column1' => 'hello', 'column2' => 'world', 'column3' => 1]) ->format(['%s', '%s', '%d']) ->where(['column4' => 5]) ->whereFormat(['%d']) ->execute();
$wpdb->delete
Delete a row in the table
WPDB::delete() ->table('wp_my_table') ->where(['column4' => 5]) ->whereFormat(['%d']) ->execute();
$wpdb->query
Perform a MySQL database query, using current database connection and optional prepares the SQL query for safe execution. Uses sprintf()-like syntax.
WPDB::query() ->query('SELECT * FROM wp_my_table WHERE column1=%d', [1]);
$wpdb->get_results
Retrieve an entire SQL result set from the database (i.e., many rows) and optional prepares the SQL query for safe execution. Uses sprintf()-like syntax.
WPDB::results() ->query('SELECT * FROM wp_my_table WHERE column1=%s LIMIT 0, 10', ['abc']);
$wpdb->get_var
Retrieve one variable from the database and optional prepares the SQL query for safe execution. Uses sprintf()-like syntax.
WPDB::getVar() ->query('SELECT COUNT(*) FROM wp_my_table WHERE column1=%d', [1]);
$wpdb->get_row
Retrieve one row from the database and optional prepares the SQL query for safe execution. Uses sprintf()-like syntax.
WPDB::getRow() ->query('SELECT column2, column3 FROM wp_my_table WHERE column1=%d', [1]);
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.