You are here : phpmysqlmysql_connect

mysql_connect() - mysql

Connects to MySQL Database.


Syntax

resource mysql_connect ([ string $server = ini_get("mysql.default_host")
 [, string $username = ini_get("mysql.default_user")
  [, string $password = ini_get("mysql.default_password")
   [, bool $new_link = false [, int $client_flags = 0 ]]]]] )


Example

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>


Output / Return Value

Connects to MySQL Database.


Limitations

This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0.


Alternatives / See Also

The MySQLi or PDO_MySQL Should be used.

MySQLi - mysqli_connect()


Reference

http://php.net/manual/en/function.mysql-connect.php