Name

Mysql::connect

Synopsis

$db = Mysql->connect($host, $database, $user, $password);

In addition to the three connect methods that are identical to Msql::connect, Mysql::connect provides a fourth method that requires an additional password argument. The first argument is the hostname or IP address of the MySQL server. If undef is passed as this argument, the module connects to the Unix-style socket on the localhost. The second argument is the name of the initial database to select. This can always be changed later with Mysql::selectdb. You may also supply undef as the second argument to select no initial database. The third argument is the username of the user connecting to the database. To successfully connect, the username must exist in the MySQL access tables. The final argument is the password of the user.

Example

use Mysql;

$db = Mysql->connect(undef,'mydata','webuser','super_secret_squirrel');
# The database handle is now connected to the local MySQL server using the
# database 'mydata'. The user name 'webuser' was used to connect who had
# the password 'super_secret_squirrel'.

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.