php mysqli两种操作方式示例

面向对象方法:

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");


if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

printf("Host information: %s\n", $mysqli->host_info);


$mysqli->close();
?>

面向过程方法:

<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");


if (!$link) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

printf("Host information: %s\n", mysqli_get_host_info($link));


mysqli_close($link);
?>

评论

© ID4710720 | Powered by LOFTER