MySQLi 連線
物件導向的風格
連線到伺服器
$conn = new mysqli("localhost","my_user","my_password");
設定預設資料庫: $conn->select_db("my_db");
連線到資料庫
$conn = new mysqli("localhost","my_user","my_password","my_db");
程式風格
連線到伺服器
$conn = mysqli_connect("localhost","my_user","my_password");
設定預設資料庫: mysqli_select_db($conn, "my_db");
連線到資料庫
$conn = mysqli_connect("localhost","my_user","my_password","my_db");
驗證資料庫連線
物件導向的風格
if ($conn->connect_errno > 0) {
trigger_error($db->connect_error);
} // else: successfully connected
程式風格
if (!$conn) {
trigger_error(mysqli_connect_error());
} // else: successfully connected