Table of Contents

Syntax

resource mysql_connect(string $host, string $user, string $pass [, $bool $newlink [, int $client_flags]])

(PHP 4, PHP 5)

$host The database server name. (can be localhost, a named host, or an IP address).
$user The mysql user account name for connecting to the database.
$pass The mysql user account password for connecting to the database.
$newlink Use this to force a new link to be established, even if an existing one already exists.
$client_flags MySQL-specific options for opening a link with the database.
RETURNS The MySQL connection resource if the connection was made successfully, false otherwise.

Possible Values for $client_flags

MYSQL_CLIENT_SSL Connect to MySQL using Secure Sockets Layer
MYSQL_CLIENT_COMPRESS Attempt to compress data sent between PHP and MySQL using GZip.
MYSQL_CLIENT_IGNORE_SPACE Allow trailing whitespace after function names (but before its arguments)
MYSQL_CLIENT_INTERACTIVE Use interactive_timeout settings instead of wait_timeout to kill a database connection.

What it Does

Creates a link to the MySQL database using the provided attributes. You need to create a link to a database before you can use any of the MySQL functions (e.g.: mysql_query).

Example

// open the mysql resource
$res = mysql_connect($server, $user, $pass);
 
// close the mysql resource
mysql_close($res);