PHP mysqli connect() İşlevi
Örnek - Nesne Yönelimli stil
MySQL sunucusuna yeni bir bağlantı açın:
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
?>
En alttaki prosedürel stil örneğine bakın.
Tanım ve Kullanım
connect() / mysqli_connect() işlevi, MySQL sunucusuna yeni bir bağlantı açar.
Sözdizimi
Nesne yönelimli stil:
$mysqli -> new mysqli(host, username, password, dbname, port, socket)
Prosedür stili:
mysqli_connect(host, username, password, dbname, port, socket)
Parametre Değerleri
Parameter | Description |
---|---|
host | Optional. Specifies a host name or an IP address |
username | Optional. Specifies the MySQL username |
password | Optional. Specifies the MySQL password |
dbname | Optional. Specifies the default database to be used |
port | Optional. Specifies the port number to attempt to connect to the MySQL server |
socket | Optional. Specifies the socket or named pipe to be used |
Teknik detaylar
Geri dönüş değeri: | MySQL sunucusuna bağlantıyı temsil eden bir nesne döndürür |
---|---|
PHP Sürümü: | 5+ |
Örnek - Prosedürel stil
MySQL sunucusuna yeni bir bağlantı açın:
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
?>
❮ PHP MySQLi Referansı