Name

sqlSelect — returns one or more fields in a single row from a SQL statement

Synopsis

my $field = $slashdb->sqlSelect($select);
my $field = $slashdb->sqlSelect($select, $from);
my $field = $slashdb->sqlSelect($select, $from, $where);
my $field = $slashdb->sqlSelect($select, $from, $where, $other);

sqlSelect builds and executes a SQL statement from its parameters. It returns a field or fields from the first returned row. In scalar context, it returns the first field. In list context, it returns the entire row. In case of error, it logs the failed SQL statement and returns a false value.

The $select parameter is required. It must be a string containing a field (or a comma-separated list of fields) to select. The $from parameter is optional. If provided, it must be a string containing a table (or a comma-separated list of tables) from which to select. The $where parameter is also optional and will be used to construct a WHERE clause. The $other parameter is also optional and will be added, verbatim, to the end of the SQL statement. It can be used to add a GROUP BY or ORDER BY clause.

Example

my $num_users = $slashdb->sqlSelect('COUNT(*)', 'users');
my ($nick, $level) = $slashdb->sqlSelect('nickname, seclev', 'users',
"uid=$uid");

Get Running Weblogs with Slash now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.