PHP-mysqli 出错回显

面向对象风格

    <?php
        $conn = new mysqli("localhost", "username", "password", "database_name");
        
        if($conn->connect_errno) {
            printf("connect filed: $s \n", $conn->connect_error);
            exit;
        }

        if(!$conn->query("SET a=1")) {
            printf("error message: %s\n", $conn->error);
        }
    ?>

面向过程风格

    <?php
        $conn = mysqli_connect("localhost", "username", "password", "database_name");
        
        if(mysqli_connect_errno()) {
            printf("connect filed: $s \n", mysqli_connect_error);
            exit;
        }

        if(!mysqli_query($conn, "SET a=1")) {
            printf("error message: %s\n", mysqli_error($link));
        }
    ?>

From: http://php.net/manual/zh/mysqli.error.php

posted @ 2017-10-24 15:40  ka1n4t  阅读(376)  评论(0编辑  收藏  举报