Mojo::MySQL5::Results - Results
use Mojo::MySQL5::Results; my $results = Mojo::MySQL5::Results->new(db => $db);
Mojo::MySQL5::Results is a container for results returned by call to $db->"query" in Mojo::MySQL5::Database.
Mojo::MySQL5::Results inherits all methods from Mojo::Base and implements the following ones.
my $array = $results->array;
Fetch one row and return it as an array reference.
# Process one row at a time while (my $next = $results->array) { say $next->[3]; }
my $collection = $results->arrays;
Fetch all rows and return them as a Mojo::Collection object containing array references.
# Process all rows at once say $results->arrays->reduce(sub { $a->[3] + $b->[3] });
my $columns = $results->columns;
Return column names as an array reference.
my $hash = $results->hash;
Fetch one row and return it as a hash reference.
# Process one row at a time while (my $next = $results->hash) { say $next->{money}; }
my $collection = $results->hashes;
Fetch all rows and return them as a Mojo::Collection object containing hash references.
# Process all rows at once say $results->hashes->reduce(sub { $a->{money} + $b->{money} });
my $num = $results->rows;
Number of rows.
my $text = $results->text;
Fetch all rows and turn them into a table with "tablify" in Mojo::Util.
do { my $columns = $results->columns; my $arrays = $results->arrays; } while ($results->more_results);
Handle multiple results.
my $affected = $results->affected_rows;
Number of affected rows by the query. The number reported is dependant from found_rows option in Mojo::MySQL5. For example
found_rows
UPDATE $table SET id = 1 WHERE id = 1
would return 1 if found_rows is set, and 0 otherwise.
my $last_id = $results->last_insert_id;
That value of AUTO_INCREMENT column if executed query was INSERT in a table with AUTO_INCREMENT column.
AUTO_INCREMENT
INSERT
my $warnings = $results->warnings_count;
Number of warnings raised by the executed query.
my $err = $results->err;
Error code receieved.
my $state = $results->state;
Error state receieved.
my $errstr = $results->errstr;
Error message receieved.
Mojo::MySQL5, Mojo::MySQL5::Database.
To install Mojo::MySQL5, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::MySQL5
CPAN shell
perl -MCPAN -e shell install Mojo::MySQL5
For more information on module installation, please visit the detailed CPAN module installation guide.