PHP mysqli_real_connect() 函數
PHP mysqli_real_connect() 函數
實例
打開一個到 MySQL 服務器的新連接:
<?php
$con=mysqli_init();
if (!$con)
{
die("mysqli_init failed");
}
if (!mysqli_real_connect($con,"localhost","my_user","my_password","my_db"))
{
die("Connect Error: " . mysqli_connect_error());
}
mysqli_close($con);
?>
$con=mysqli_init();
if (!$con)
{
die("mysqli_init failed");
}
if (!mysqli_real_connect($con,"localhost","my_user","my_password","my_db"))
{
die("Connect Error: " . mysqli_connect_error());
}
mysqli_close($con);
?>
定義和用法
mysqli_real_connect() 函數打開一個到 MySQL 服務器的新連接。
mysqli_real_connect() 函數與 mysqli_connect() 函數在以下幾個方面存在差異:
- mysqli_real_connect() 要求一個由 mysqli_init() 創建的有效的對象。
- mysqli_real_connect() 可以與 mysqli_options() 一同使用來設置連接的不同選項。
- mysqli_real_connect() 有一個 flag 參數。
語法
mysqli_real_connect(connection,host,username,password,dbname,port,socket,flag);
參數 | 描述 |
---|---|
connection | 必需。規定要使用的 MySQL 連接。 |
host | 可選。規定主機名或 IP 地址。 |
username | 可選。規定 MySQL 用戶名。 |
password | 可選。規定 MySQL 密碼。 |
dbname | 可選。規定要使用的默認數據庫。 |
port | 可選。規定嘗試連接到 MySQL 服務器的端口號。 |
socket | 可選。規定 socket 或要使用的已命名 pipe。 |
flag | 可選。規定不同的連接選項。可能的值:
|
技術細節
返回值: | 如果成功則返回 TRUE,如果失敗則返回 FALSE。 |
---|---|
PHP 版本: | 5+ |

相關文章
- PHP 簡介
- PHP echo 和 print 語句
- PHP EOF(heredoc) 使用說明
- PHP 常量
- PHP 面向對象
- PHP $_POST 變量
- PHP Cookie
- PHP 發送電子郵件
- PHP Secure E-mails
- PHP array_fill() 函數
- PHP array_intersect_ukey() 函數
- PHP array_map() 函數
- PHP array_shift() 函數
- PHP array_sum() 函數
- PHP array_udiff_uassoc() 函數
- PHP each() 函數
- PHP sizeof() 函數
- PHP Libxml 函數
- PHP Mail 函數
- PHP 雜項 函數