Name
mysql_connect
Synopsis
cresource mysql_connect([stringhostname
[, stringusername
[, stringpassword
[, booleannew_connection
]]]])
Used to
establish a connection to the MySQL DBMS. The function returns a
connection resource handle on success that can be used to access
databases through subsequent function calls. The function returns
false
on failure.
The function has four optional parameters. The first is the
hostname
of the DBMS that can include an
optional port
number. The
hostname
parameter is usually set to
localhost
when the MySQL DBMS and the web server
are running on the same machine. A default port for MySQL of 3306 is
assumed if the port is omitted.
The second and third parameters—a
username
and
password
—are MySQL DBMS username and
password credentials. These are the same username and password used
to access the DBMS though the command-line monitor
mysql
.
If a second call is made to the function in the same script with the
same first three parameters, a new connection is not opened. Instead,
the function just returns the connection resource handle of the
existing open connection. In the upcoming PHP 4.2 release, you should
be able to override this behavior by supplying a fourth
new_connection
parameter. When it is set
to true
, a new connection will always be opened.
If all parameters are omitted, the
hostname
and port default to
localhost:3306
, the
username
defaults to the name of the user
that owns the MySQL DBMS server process, and the
password
defaults to an empty ...
Get Managing & Using MySQL, 2nd Edition 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.