mysql_connect Open a connection to a MySQL Server &reftitle.description; resourcemysql_connect stringserver stringusername stringpassword boolnew_link intclient_flags Opens or reuses a connection to a MySQL server. &reftitle.parameters; server The MySQL server. It can also include a port number. e.g. "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for the localhost. If the PHP directive mysql.default_host is undefined (default), then the default value is 'localhost:3306'. In &sqlsafemode;, this parameter is ignored and value 'localhost:3306' is always used. username The username. Default value is defined by mysql.default_user. In &sqlsafemode;, this parameter is ignored and the name of the user that owns the server process is used. password The password. Default value is defined by mysql.default_password. In &sqlsafemode;, this parameter is ignored and empty password is used. new_link If a second call is made to mysql_connect with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect always open a new link, even if mysql_connect was called before with the same parameters. In &sqlsafemode;, this parameter is ignored. client_flags The client_flags parameter can be a combination of the following constants: 128 (enable LOAD DATA LOCAL handling), MYSQL_CLIENT_SSL, MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE or MYSQL_CLIENT_INTERACTIVE. Read the section about for further information. In &sqlsafemode;, this parameter is ignored. &reftitle.returnvalues; Returns a MySQL link identifier on success, or &false; on failure. &reftitle.changelog; &Version; &Description; 4.3.0 Added the client_flags parameter. 4.2.0 Added the new_link parameter. 3.0.10 Added support for ":/path/to/socket" with server. 3.0.0 Added support for ":port" with server. &reftitle.examples; <function>mysql_connect</function> example ]]> <function>mysql_connect</function> example using <literal>hostname:port</literal> syntax ]]> <function>mysql_connect</function> example using ":/path/to/socket" syntax ]]> &reftitle.notes; Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as in your PHP configuration and leave the server field blank. The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling mysql_close. You can suppress the error message on failure by prepending a @ to the function name. &reftitle.seealso; mysql_pconnect mysql_close