Automattic\WooCommerce\Database\Migrations\CustomOrderTable

PostsToOrdersMigrationController::db_query()privateWC 1.0

Execute a database query and log any errors.

Метод класса: PostsToOrdersMigrationController{}

No Hooks.

Return

true|false. True if the query succeeded, false if there were errors.

Usage

// private - for code of main (parent) class only
$result = $this->db_query( $query ): bool;
$query(string) (required)
The SQL query to execute.

Code of PostsToOrdersMigrationController::db_query() WC 7.1.0

private function db_query( string $query ): bool {
	$wpdb = WC()->get_global( 'wpdb' );

	try {
		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
		$wpdb->query( $query );
	} catch ( \Exception $exception ) {
		$exception_class = get_class( $exception );
		$this->error_logger->error(
			"PostsToOrdersMigrationController: when executing $query: ($exception_class) {$exception->getMessage()}, {$exception->getTraceAsString()}",
			array(
				'source'    => self::LOGS_SOURCE_NAME,
				'exception' => $exception,
			)
		);
		return false;
	}

	$error = $wpdb->last_error;
	if ( '' !== $error ) {
		$this->error_logger->error(
			"PostsToOrdersMigrationController: when executing $query: $error",
			array(
				'source' => self::LOGS_SOURCE_NAME,
				'error'  => $error,
			)
		);
		return false;
	}

	return true;
}