Nile::Database - SQL database manager.
# set database connection params to connect # $args{driver}, $args{host}, $args{dsn}, $args{port}, $args{attr} # $args{name}, $args{user}, $args{pass} # if called without params, it will try to load from the default config vars. $dbh = $self->me->db->connect(%args);
$self->me->db->dbh;
Current database connection handle.
$self->me->db->connect(%args);
Connect to the database. If %args empty, it will try to get args from the config object. Returns the database connection handle is success.
$self->me->db->disconnect;
Disconnect from this connection handle.
$self->me->db->run($qry);
Run query using the DBI do command or abort if error.
$self->me->db->do($qry);
Run query using the DBI do command and ignore errors.
$sth = $self->me->db->exec($qry);
Prepare and execute the query and return the statment handle.
$self->me->db->begin_work;
Enable transactions (by turning AutoCommit off) until the next call to commit or rollback. After the next commit or rollback, AutoCommit will automatically be turned on again.
$self->me->db->commit;
Commit (make permanent) the most recent series of database changes if the database supports transactions and AutoCommit is off.
$self->me->db->rollback;
Rollback (undo) the most recent series of uncommitted database changes if the database supports transactions and AutoCommit is off.
$self->me->db->quote($value); $self->me->db->quote($value, $data_type);
Quote a string literal for use as a literal value in an SQL statement, by escaping any special characters (such as quotation marks) contained within the string and adding the required type of outer quotation marks.
# select id from users. return one column array from all rows @cols = $self->me->db->col($qry); $cols_ref = $self->me->db->col($qry);
Return one column array from all rows
# select id, email, fname, lname from users @row = $self->me->db->row($qry);
Returns one row as array.
# select id, fname, lname, email from users @rows = $self->me->db->rows($qry); $rows_ref = $self->me->db->rows($qry);
Returns all matched rows as array or array ref.
# select * from users where id=$id limit 1 %user = $self->me->db->hash($qry); $user_ref = $self->me->db->hash($qry);
Returns one row as a hash or hash ref
# select * from users where id=$id limit 1 $row_obj = $self->me->db->row_object($qry); print $row_obj->email; print $row_obj->fname; print $row_obj->lname;
Returns one row as object with columns names as object properties.
%hashes = $self->me->db->hashes($qry, $col); $hashes_ref = $self->me->db->hashes($qry, $col);
Returns list or hashes of all rows. Each hash element is a hash of one row
# select id, user from users %hash = $self->me->db->colhash($qry);
Returns all rows as a hash of the first column as the keys and the second column as the values.
# select email from users where id=123. return one column value $value = $self->me->db->value($qry);
Returns one column value from one row.
$id = $self->me->db->insertid;
Returns the last insert id from auto increment.
$self->me->db->db_error;
Aborts the application and display the last database error message.
This project is available on github at https://github.com/mewsoft/Nile.
Please visit the project's homepage at https://metacpan.org/release/Nile.
Source repository is at https://github.com/mewsoft/Nile.
Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Nile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nile
CPAN shell
perl -MCPAN -e shell install Nile
For more information on module installation, please visit the detailed CPAN module installation guide.