Hướng dẫn what does mysqli_query return if empty? - mysqli_query trả về cái gì nếu trống?

10

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Tôi có mã sau và tôi muốn biết liệu mysqli_query có trả lại bất kỳ hàng nào không và nếu trả lại lỗi.

$result = mysqli_query($connection, "SELECT * FROM users");
    
if ($result == "") {
    echo "No records found";
} else {
    echo "There is at least one record in the database";
}

Tôi đang gặp rắc rối nếu kết quả trở lại như trống. Tôi đã thử sử dụng một số thứ và không thể tìm ra cách để nó hoạt động chính xác nếu không tìm thấy gì.

Hướng dẫn what does mysqli_query return if empty? - mysqli_query trả về cái gì nếu trống?

Dharman ♦

28.1K21 Huy hiệu vàng75 Huy hiệu bạc127 Huy hiệu đồng21 gold badges75 silver badges127 bronze badges

Đã hỏi ngày 8 tháng 6 năm 2013 lúc 6:09Jun 8, 2013 at 6:09

0

Sử dụng MySQLI_NUM_ROWS để kiểm tra xem bất kỳ hàng nào có được trả về hay không.

Đã trả lời ngày 8 tháng 6 năm 2013 lúc 6:11Jun 8, 2013 at 6:11

AnanthananthAnanth

4.0822 Huy hiệu vàng19 Huy hiệu bạc26 Huy hiệu đồng2 gold badges19 silver badges26 bronze badges

0

Sử dụng mysqli_num_rows như thế này

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}

Hướng dẫn what does mysqli_query return if empty? - mysqli_query trả về cái gì nếu trống?

Dharman ♦

28.1K21 Huy hiệu vàng75 Huy hiệu bạc127 Huy hiệu đồng21 gold badges75 silver badges127 bronze badges

Đã hỏi ngày 8 tháng 6 năm 2013 lúc 6:09Jun 8, 2013 at 6:22

if(empty($result))
{
    echo("email was not found");
}

Sử dụng MySQLI_NUM_ROWS để kiểm tra xem bất kỳ hàng nào có được trả về hay không.Jun 8, 2013 at 6:19

Hướng dẫn what does mysqli_query return if empty? - mysqli_query trả về cái gì nếu trống?

1

mysqli_query

8 năm trước

hunreal tại gmail dot com -- mysqli_queryPerforms a query on the database

18 năm trước

Thomas Dekker ¶

Popere Dot Noel tại Yahoo Dot Com ¶ mysqli::query(string $query, int $result_mode = MYSQLI_STORE_RESULT): mysqli_result|bool

9 năm trước(mysqli $mysql, string $query, int $result_mode = MYSQLI_STORE_RESULT): mysqli_result|bool

Omidbahrami1990 tại Gmail Dot Com ¶mysqli_real_query() followed by either mysqli_use_result() or mysqli_store_result().

Blinki Bill, Argodak tại Yahoo Dot Com ¶:

5 năm trướcmysqli_query() that is longer than

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
3 of the server, the returned error codes are different depending on whether you are using MySQL Native Driver (
if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
4) or MySQL Client Library (
if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
5). The behavior is as follows:

  • David Marcus ¶

  • Mysqli_query return giá trị nào?

  • Trả về các giá trị ¶ Đối với các truy vấn thành công tạo ra một tập kết quả, chẳng hạn như chọn, hiển thị, mô tả hoặc giải thích, mysqli_query () sẽ trả về đối tượng mysqli_result. Đối với các truy vấn thành công khác, mysqli_query () sẽ trả về đúng.

Hàm mysqli_query () làm gì?

Hàm mySQLI_Query () chấp nhận giá trị chuỗi đại diện cho một truy vấn là một trong các tham số và, thực thi/thực hiện truy vấn đã cho trên cơ sở dữ liệu.

Mysqli_num_rows trở lại là gì?mysqli object returned by mysqli_connect() or mysqli_init()

Hàm mysqli_num_rows () trả về số lượng hàng trong một tập kết quả.

Làm cách nào để kiểm tra xem mysqli có trống không?

Đối với các truy vấn thành công khác mysqli_query () sẽ trả về true. Kết quả vẫn có thể trống ngay cả khi nó thành công. Nếu bạn sử dụng PDO, như đề xuất ở trên. Bạn nhận được một mảng trở lại (mảng trống nếu kết quả trống) để bạn có thể thực hiện sizeof ($ mảng) hoặc đếm (mảng $) để kiểm tra xem bạn có 0 kết quả hay không.

(Php 5, Php 7, Php 8)

MySQLI :: Truy vấn - MySQLI_Query - Thực hiện truy vấn trên cơ sở dữ liệu (default) - returns a mysqli_result object with buffered result set.

Sự mô tả - returns a mysqli_result object with unbuffered result set. As long as there are pending records waiting to be fetched, the connection line will be busy and all subsequent calls will return error

if(empty($result))
{
    echo("email was not found");
}
5. To avoid the error all records must be fetched from the server or the result set must be discarded by calling mysqli_free_result().

Phong cách hướng đối tượng (available with mysqlnd) - the query is performed asynchronously and no result set is immediately returned. mysqli_poll() is then used to get results from such queries. Used in combination with either MYSQLI_STORE_RESULT or

if(empty($result))
{
    echo("email was not found");
}
4 constant.

publicMysqli :: truy vấn (chuỗi $query, int $result_mode = MYSQLI_STORE_RESULT): mysqli_result | bool

mysqli_query (mysqli $mysql, chuỗi $query, int $result_mode = MYSQLI_STORE_RESULT): mysqli_result | bool

if(empty($result))
{
    echo("email was not found");
}
9 on failure. For successful queries which produce a result set, such as
Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...
0 or
Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...
1, mysqli_query() will return a mysqli_result object. For other successful queries, mysqli_query() will return
Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...
2
.

Đối với các truy vấn không phải DML (không chèn, cập nhật hoặc xóa), chức năng này tương tự như gọi mysqli_real_query () theo sau là mysqli_use_result () hoặc mysqli_store_result ().

Ghi chú:mysqli::query() example

Thomas Dekker ¶

Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...
3

Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...
4

Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...
5

Popere Dot Noel tại Yahoo Dot Com ¶

Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...
3

Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...
4

Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...
8

Các ví dụ trên sẽ xuất ra một cái gì đó tương tự như:

Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...

Xem thêm

  • mysqli_real_query () - thực hiện truy vấn SQL
  • mysqli_multi_query () - thực hiện một hoặc nhiều truy vấn trên cơ sở dữ liệu
  • mysqli_prepare () - Chuẩn bị một câu lệnh SQL để thực thi
  • mysqli_free_result () - giải phóng bộ nhớ liên quan đến kết quả

Nuntius ¶

14 năm trước

Table myCity successfully created.
Select returned 10 rows.

Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...
9

mysqli_query0

mysqli_query1

mysqli_query2

mysqli_query3

mysqli_query4

họ tại Gmail dot com

11 năm trước

mysqli_query5

mysqli_query6

mysqli_query7

Petrus.jvr ¶

11 năm trước

mysqli_query8

mysqli_query9

mysqli_query7

Petrus.jvr ¶

Ẩn danh ¶

mysqli_num_rows1

mysqli_num_rows2

mysqli_query7

4 năm trước

Người nổi ¶

mysqli_num_rows4

mysqli_num_rows5

mysqli_num_rows6

mysqli_num_rows7

mysqli_num_rows8

mysqli_num_rows9

16 năm trước

Đăng ký tại jdfoxmicro dot com

$query0

$query1

$query2

$query3

$query4

mysqli_query7

12 năm trước

XA tại sagexa dot com ¶

$query6

1 tháng trước

14 năm trước

$query7

$query8

$query9

mysqli_query7

họ tại Gmail dot com

11 năm trước

$result_mode1

$result_mode2

Petrus.jvr ¶

Ẩn danh ¶

Người nổi ¶

$result_mode4

$result_mode5

$result_mode6

$result_mode7

$result_mode8

16 năm trước

Đăng ký tại jdfoxmicro dot com

$result_mode9

MYSQLI_STORE_RESULT0

mysqli_query7

12 năm trước

XA tại sagexa dot com ¶

MYSQLI_STORE_RESULT2

MYSQLI_STORE_RESULT3

MYSQLI_STORE_RESULT4

1 tháng trước

CEO tại L-i-e Dot Com ¶

MYSQLI_STORE_RESULT5

MYSQLI_STORE_RESULT6

MYSQLI_STORE_RESULT7

MYSQLI_STORE_RESULT8

MYSQLI_STORE_RESULT9

mysqli_query7

jcwebb tại dicoe dot com ¶

Đăng ký tại jdfoxmicro dot com

$mysql1

$mysql2

mysqli_query7

12 năm trước

XA tại sagexa dot com ¶

$mysql4

$mysql5

$mysql6

$mysql7

mysqli_query7

1 tháng trước

Ẩn danh ¶

$mysql9

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
00

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
01

4 năm trước

XA tại sagexa dot com ¶

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
02

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
03

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
04

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
05

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
06

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
07

mysqli_query7

Petrus.jvr ¶

Ẩn danh ¶

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
09

4 năm trước

Ẩn danh ¶

if (mysqli_num_rows($result) == 0) {
    echo "email was not found";
} else {
    echo "email was found";
}
10

Mysqli_query return giá trị nào?

Trả về các giá trị ¶ Đối với các truy vấn thành công tạo ra một tập kết quả, chẳng hạn như chọn, hiển thị, mô tả hoặc giải thích, mysqli_query () sẽ trả về đối tượng mysqli_result.Đối với các truy vấn thành công khác, mysqli_query () sẽ trả về đúng.mysqli_result object. For other successful queries, mysqli_query() will return true .

Hàm mysqli_query () làm gì?

Hàm mySQLI_Query () chấp nhận giá trị chuỗi đại diện cho một truy vấn là một trong các tham số và, thực thi/thực hiện truy vấn đã cho trên cơ sở dữ liệu.executes/performs the given query on the database.

Mysqli_num_rows trở lại là gì?

Hàm mysqli_num_rows () trả về số lượng hàng trong một tập kết quả.the number of rows in a result set.

Làm cách nào để kiểm tra xem mysqli có trống không?

Đối với các truy vấn thành công khác mysqli_query () sẽ trả về true.Kết quả vẫn có thể trống ngay cả khi nó thành công.Nếu bạn sử dụng PDO, như đề xuất ở trên.Bạn nhận được một mảng trở lại (mảng trống nếu kết quả trống) để bạn có thể thực hiện sizeof ($ mảng) hoặc đếm (mảng $) để kiểm tra xem bạn có 0 kết quả hay không.sizeof($array) or count($array) to check if you have 0 results or not.