Connection

NAME

DB::MySQL::Connection -- Database connection object

SYNOPSIS

my $my = DB::MySQL.new;

my $db = $my.db;

say "Good connection" if $db.ping;

say $db.query('select * from foo where x = ?', 27).hash;

my $sth = $db.prepare('select * from foo where x = ?'); # DB::MySQL::Statement

$db.execute('insert into foo (x,y) values (1,2)'); # No placeholder args

$db.begin; $db.commit; $db.rollback;

$db.finish; # Finished with database connection, return to idle pool

DESCRIPTION

Always allocate from a DB::MySQL object with the .db method. Use .finish to return the database connection to the pool when finished.

METHODS

finish()

Return this database connection to the connection pool in the parent DB::MySQL object.

ping()

Returns True if the connection to the server is active.

execute(Str:D $sql, Bool :$finish, Bool :$store)

Executes the sql statement. :finish causes the database connection to be finished after the command executes. :store (defaults to True) causes the results to be retrieved from server to client at once instead of retrieved row by row.

If results are returned (e.g. a 'SELECT'), returns a DB::MySQL::Result (actually a DB::MySQL::NonStatementResult because it is not prepared) with the result, otherwise (e.g. 'INSERT', 'UPDATE', etc.) returns the number of affected rows.

prepare(Str:D $query, Bool :$nocache --> DB::MySQL::Statement)

Prepares the SQL query, returning a DB::MySQL::Statement object with the prepared query. These are cached in the database connection object, so if the same query is prepared again, the previous statement is returned. You can avoid the statement caching by setting :nocache to True (or by calling prepare-nocache()).

prepare-nocache(Str:D $query --> DB::MySQL::Statement)

Prepares the SQL query, returning a DB::MySQL::Statement object with the prepared query.

query(Str:D $query, Bool :$finish, Bool :$nocache, *@args)

prepares, then executes the query with the supplied arguments.

begin()

Begins a new database transaction. Returns the DB::MySQL::Connection object.

commit()

Commits an active database transaction. Returns the DB::MySQL::Connection object.

rollback()

Rolls back an active database transaction. If the database is finished with an active transaction, it will be rolled back automatically. Returns the DB::MySQL::Connection object.

DB::MySQL v0.8

MySQL access for Perl6

Authors

  • Curt Tilmes
  • David Romero

License

BSD-2-Clause

Dependencies

DBNativeLibsNativeCallJSON::Fast

Test Dependencies

Provides

  • DB::MySQL
  • DB::MySQL::Connection
  • DB::MySQL::Converter
  • DB::MySQL::Native
  • DB::MySQL::Result
  • DB::MySQL::Statement

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.