Mysqli_query kết quả

my_personal_contacts

  • Connected with MySQL by phpMyAdmin, v. v.  
  • Tạo cơ sở dữ liệu có tên my_person_contacts
  • Thi tập lệnh hiển thị bên dưới để tạo bảng và chèn một số dữ liệu demo
  • TẠO BẢNG NẾU KHÔNG TỒN TẠI `my_contacts` [

    `id` int[11] KHÔNG NULL AUTO_INCREMENT,

    `full_names` varchar[255] KHÔNG NULL,

    `giới tính` varchar[6] KHÔNG NULL,

    `contact_no` varchar[75] KHÔNG NULL,

    `email` varchar[255] KHÔNG NULL,

    `city` varchar[255] KHÔNG NULL,

    `quốc gia` varchar[255] KHÔNG NULL,

    ] ENGINE = InnoDB  DEFAULT CHARSET = latin1 AUTO_INCREMENT = 5 ;

    CHÈN VÀO `my_contacts` [

    [1, 'Zeus', 'Nam', '111', 'zeus@olympus. tấn. co', 'Agos', 'Hy Lạp'],

    [2, 'Athena', 'Nữ', '123', 'athena@olympus. tấn. co', 'Athens', 'Hy Lạp'],

    [3, 'Jupiter', 'Nam', '783', 'jupiter@planet. điểm. co', 'Rome', 'Ý'],

    [4, 'Venus', 'Female', '987', 'venu @planet. điểm. co', 'Mars', 'Ý'];


    $mysqli = new mysqli["localhost", "my_user", "my_password", "world"];

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }

    /* Create table doesn't return a resultset */
    if [$mysqli->query["CREATE TEMPORARY TABLE myCity LIKE City"] === TRUE] {
        printf["Table myCity successfully created.\n"];
    }

    /* Select queries return a resultset */
    if [$result = $mysqli->query["SELECT Name FROM City LIMIT 10"]] {
        printf["Select returned %d rows.\n", $result->num_rows];

        /* free result set */
        $result->close[];
    }

    /* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
    if [$result = $mysqli->query["SELECT * FROM City", MYSQLI_USE_RESULT]] {

        /* Note, that we can't execute any functions which interact with the
           server until result set was closed. All calls will return an
           'out of sync' error */
        if [!$mysqli->query["SET @a:='this will not work'"]] {
            printf["Error: %s\n", $mysqli->error];
        }
        $result->close[];
    }

    ________số 8_______

    $link = mysqli_connect["localhost", "my_user", "my_password", "world"];

    /* check connection */
    if [mysqli_connect_errno[]] {
        printf["Connect failed: %s\n", mysqli_connect_error[]];
        exit[];
    }

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    0

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    1

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    2

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    3

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    4

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    5

    Trả về FALSE khi thất bại. Đối với các truy vấn CHỌN, HIỂN THỊ, MÔ TẢ hoặc GIẢI THÍCH thành công, mysqli_query[] sẽ trả về một đối tượng mysqli_result. Đối với các truy vấn thành công khác, mysqli_query[] sẽ trả về TRUE

    Định hướng của đối tượng

    $mysqli = new mysqli["localhost", "my_user", "my_password", "world"];

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }

    /* Create table doesn't return a resultset */
    if [$mysqli->query["CREATE TEMPORARY TABLE myCity LIKE City"] === TRUE] {
        printf["Table myCity successfully created.\n"];
    }

    /* Select queries return a resultset */
    if [$result = $mysqli->query["SELECT Name FROM City LIMIT 10"]] {
        printf["Select returned %d rows.\n", $result->num_rows];

        /* free result set */
        $result->close[];
    }

    /* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
    if [$result = $mysqli->query["SELECT * FROM City", MYSQLI_USE_RESULT]] {

        /* Note, that we can't execute any functions which interact with the
           server until result set was closed. All calls will return an
           'out of sync' error */
        if [!$mysqli->query["SET @a:='this will not work'"]] {
            printf["Error: %s\n", $mysqli->error];
        }
        $result->close[];
    }

    ________số 8_______

    $link = mysqli_connect["localhost", "my_user", "my_password", "world"];

    /* check connection */
    if [mysqli_connect_errno[]] {
        printf["Connect failed: %s\n", mysqli_connect_error[]];
        exit[];
    }

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    0

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    1

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    2

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    3

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    4

    /* check connection */
    if [$mysqli->connect_errno] {
        printf["Connect failed: %s\n", $mysqli->connect_error];
        exit[];
    }
    5

    Kết quả của mysqli_query là gì?

    Đối với các truy vấn thành công tạo ra một tập hợp kết quả, chẳng hạn như SELECT, SHOW, DESCRIBE hoặc EXPLAIN , mysqli_query[] sẽ trả về một đối tượng mysqli_result . Đối với các truy vấn thành công khác, mysqli_query[] sẽ trả về true.

    Làm cách nào để lấy dữ liệu từ mysqli_query?

    Tìm nạp dữ liệu bằng PHP Script . Hàm này nhận hai tham số và trả về TRUE nếu thành công hoặc FALSE nếu thất bại. PHP uses mysqli query[] or mysql_query[] function to select records from a MySQL table. This function takes two parameters and returns TRUE on success or FALSE on failure.

    mysqli_result trả về cái gì?

    Lớp mysqli_result ¶ . the result set obtained from a query against the database.

    Truy vấn [] trả về gì trong PHP?

    Giá trị trả về ¶ . Đối với các loại câu lệnh SQL khác, INSERT, UPDATE, DELETE, DROP, v.v., mysql_query[] trả về true nếu thành công hoặc false nếu có lỗi. a resource on success, or false on error. For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query[] returns true on success or false on error.

    Chủ Đề