PHP mysql_connect() function
Definition and Usage
The mysql_connect() function opens a non-persistent MySQL connection.
Syntax
mysql_connect(server,user,pwd,newlink,clientflag)
Parameters | Description |
---|---|
server |
Optional. Specifies the server to connect to. It can include a port number, such as "hostname:port", or a path to a local socket, such as ":/path/to/socket" for localhost. If the PHP directive mysql.default_host is undefined (the default case), the default value is 'localhost:3306'. |
user | Optional. Username. The default value is the username of the server process owner. |
pwd | Optional. Password. The default value is an empty password. |
newlink | Optional. If mysql_connect() is called a second time with the same parameters, it will not establish a new connection but will return the identifier of the already opened connection. The parameter new_link changes this behavior and makes mysql_connect() always open a new connection, even if mysql_connect() has been called previously with the same parameters. |
clientflag |
Opcjonalnie.clientflags Parametr może być kombinacją poniższych stałych:
|
Wartość zwracana
Jeśli pomyślnie, zwraca identyfikator połączenia MySQL, w przeciwnym razie zwraca FALSE.
Wskazówki i komentarze
Komentarz:Po zakończeniu skryptu połączenie z serwerem jest zamknięte, chyba że wcześniej wyraźnie zostało zwołane mysql_close() Zamknięte.
Wskazówka:Aby utworzyć trwałe połączenie, użyj mysql_pconnect() Funkcja.
Przykład
<?php $con = mysql_connect("localhost","mysql_user","mysql_pwd"); if (!$con) { die('Nie można połączyć: ' . mysql_error()); } // Niektóry kod... mysql_close($con); ?>