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