← All built-ins / mysql_connect()

mysql_connect()

mysql_connect(...$args): mixed

Parameters

NameTypeDescription
$hoststringMySQL/MariaDB host (TCP)
$portintport (default 3306)optional
$userstringuser nameoptional
$passstringpasswordoptional
$dbstringdatabase 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.

See also

mysql_query()mysql_exec()mysql_escape()