Name
mysql_connect()
Synopsis
mysql_connect(server[:port|socket], user, password[,new_link,flags])
Use this function to start a MySQL connection. The first
argument of the function is the server name. If none is specified,
localhost is assumed. A port may be specified
with the server name (separated by a colon) or a socket along with its
path. If no port is given, port 3306 is assumed. The username is to be
given as the second argument and the user’s password as the third. If
a connection is attempted that uses the same parameters as a previous
one, the existing connection will be used and a new connection link
will not be created unless new_link is
specified as the fourth argument of this function. As an optional
fifth argument, client flags may be given for the MySQL constants
MYSQL_CLIENT_COMPRESS,
MYSQL_CLIENT_IGNORE_SPACE,
MYSQL_CLIENT_INTERACTIVE, and
MYSQL_CLIENT_SSL. The function returns a connection
identifier if successful; it returns false if it’s unsuccessful. Use
mysql_close() to close a connection created
by mysql_connect(). Here is an
example:
#!/usr/bin/php -q
<?
mysql_connect('localhost', 'ricky', 'adams');
mysql_select_db('workrequests');
...To be able to identify the connection link later, especially
when a script will be using more than one link, capture the results of
mysql_connect(). Here is a complete script
that sets up two connections to MySQL and captures the resource
identification number for each link:
#!/usr/bin/php -q <? $user1 = 'elvis'; $user2 = 'fats'; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access