Name

Msql::connect

Synopsis

$db = Msql->connect;
$db = Msql->connect($host);
$db = Msql->connect($host, $database);

Establishes a connection between your Perl program and the Msql server. There are three versions of the function. With no arguments, a connection is made to the Msql Unix socket on the local host with no database defined. This is the most efficient connection. If one scalar argument is present, that argument is taken to be the hostname or IP address of the mSQL server. A connection is then made to that server with no database set. If two scalar arguments are present, the first is taken to be the host of the mSQL server and the second is the name of the desired database. The program then makes a connection to the given server and selects the given database. The value returned is a reference to an object called the “database handle.” All communication with the database server itself takes places through this object. If the connection fails for any of the above cases, undef is returned and the error is placed in $Msql::db_errstr.

Example

use Msql;

# Connect to the localhost Unix socket
my $db = Msql->connect;

# Or...
# Connect to host 'www.myserver.com' with no database defined
my $db = Msql->connect('www.myserver.com');

# Or...
# Connect to host 'www.myserver.com' and select database 'mydata'
my $db = Msql->connect('www.myserver.com','mydata');

Get MySQL and mSQL 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.