Builder::count( string|null $column_name = null )
Execute a COUNT() call against the DB using the provided query elements.
Contents
Parameters
- $column_name
-
(string|null) (Optional) The name of the column used for the count, '*` otherwise.
Default value: null
Return
(int)
Source
File: src/Events/Custom_Tables/V1/Models/Builder.php
public function count( $column_name = null ) {
if ( $this->invalid ) {
return 0;
}
global $wpdb;
if ( $column_name === null ) {
$this->operation = 'SELECT COUNT(*)';
} else {
$this->operation = $wpdb->prepare( 'SELECT COUNT(%s)', $column_name );
}
// If the query is invalid, don't return a single result.
if ( $this->invalid ) {
return 0;
}
$SQL = $this->get_sql();
$this->queries[] = $SQL;
if ( $this->execute_queries ) {
return (int) $wpdb->get_var( $SQL );
}
return 0;
}
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |