pronamic/wp-db

Database library for WordPress.

dev-main 2022-11-16 13:37 UTC

This package is auto-updated.

Last update: 2024-12-16 18:31:07 UTC


README

Examples

<?php

$database = new Database();

$payments_table = new Table(
	'mollie_payments',
	[
		new Column( 'id', 'BIGINT(16) UNSIGNED NOT NULL AUTO_INCREMENT', '%d' ),
		new Column( 'created', 'TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP', '%s' ),
		new Column( 'account_post_id', 'BIGINT(16) UNSIGNED DEFAULT NULL', '%s' ),
		new Column( 'mollie_id', 'VARCHAR(20) DEFAULT NULL', '%s' ),
		new Column( 'mode', 'VARCHAR(20) DEFAULT NULL', '%s' ),
		new Column( 'created_at', 'DATETIME DEFAULT NULL', '%s' ),
		new Column( 'status', 'VARCHAR(20) DEFAULT NULL', '%s' ),
		new Column( 'is_cancelable', 'BOOL DEFAULT NULL', '%d' ),
		new Column( 'paid_at', 'DATETIME DEFAULT NULL', '%s' ),
		new Column( 'amount', 'NUMERIC(15,2) DEFAULT NULL', '%s' ),
		new Column( 'description', 'VARCHAR(200) DEFAULT NULL', '%s' ),
		new Column( 'method', 'VARCHAR(20) DEFAULT NULL', '%s' ),
		new Column( 'json', 'TEXT DEFAULT NULL', '%s' ),
	],
	'
	PRIMARY KEY  (id),
	UNIQUE KEY mollie (mollie_id)
	'
);

$payments_table->primary_key    = 'id';
$payments_table->updated_at_key = null;
$payments_table->created_at_key = null;

$database->register_table( $payments_table );

$database->install();
<?php

$payments_table = $database->get_table( 'mollie_payments' );

$condition = [
	'mollie_id' => $payment->id,
];

$data = [

];

$payment_row = $payments_table->first_row( $condition );

if ( null !== $payment_row ) {
	$payments_table->update( $values, $payment_row->id );
}

if ( null === $payment_row ) {
	$id = $payments_table->insert( $data );
}

Resources