MySQL
NAME
DB::MySQL -- MySQL database access for Perl 6
SYNOPSIS
my $my = DB::MySQL.new; # You can pass in connection information if you want.
say $my.query('select 42').value; # 42
$my.execute('insert into foo (x,y) values (1,2)');
for $my.query('select * from foo').arrays -> @row { say @row; }
for $my.query('select * from foo').hashes -> %row { say %row; }
DESCRIPTION
The main DB::MySQL object. It manages a pool of database connections
(DB::MySQL::Connection), creating new ones as needed and caching idle
ones.
It has some methods that simply allocate a database connection, call the same method on that connection, then immediately return the connection to the pool.
METHODS
new(:$host, :$port, :$database, :$user, :$password, :$socket, :$flags, :$default-file, :$group, :$connect-timeout, :$read-timeout, :$write-timeout)
db()
Allocate a DB::MySQL::Connection object, either using a cached one from the
pool of idle connections, or creating a new one.
query(Str:D $sql, Bool :$finish, Bool :$nocache)
Allocates a database connection and perform the query, then return the connection to the pool. :finish causes the connection to return to the pool after use, :nocache causes the prepared statement not to be cached for later use.
If the query returns results, returns a DB::MySQL::Result object with the
result.
execute(Str:D $sql, Bool :$finish, Bool :$store)
Allocates a database connection, executes the SQL statement, then returns the
connection to the pool. :finish causes the connection to return to the pool
after use, :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.
finish()
Destroys all the pooled connections and the object itself.