← All built-ins / mysql_connect()
mysql_connect()
mysql_connect(...$args): mixed
Parameters
| Name | Type | Description |
|---|---|---|
| $host | string | MySQL/MariaDB host (TCP) |
| $port | int | port (default 3306)optional |
| $user | string | user nameoptional |
| $pass | string | passwordoptional |
| $db | string | database to selectoptional |
Return value
Connection handle for mysql_query/mysql_exec, or false on failure.
Example
$c = mysql_connect("localhost", 3306, "root", "", "test");
echo $c ? "connected" : "no-server (ok offline)";
if ($c) { mysql_close($c); }no-server (ok offline)
This call needs a real environment (window, server, database or stdin) — the snippet above shows the typical usage shape.