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ì.
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";
}
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
1
mysqli_query
8 năm trước
hunreal tại gmail dot com -- mysqli_query — Performs 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
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:if [mysqli_num_rows[$result] == 0] { echo "email was not found"; } else { echo "email was found"; }
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
4 constant. if[empty[$result]]
{
echo["email was not found"];
}
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
9 on failure. For successful queries which produce a result set, such as if[empty[$result]]
{
echo["email was not found"];
}
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_query
0
mysqli_query
1
mysqli_query
2
mysqli_query
3
mysqli_query
4họ tại Gmail dot com ¶
11 năm trước
mysqli_query
5
mysqli_query
6
mysqli_query
7Petrus.jvr ¶ ¶
11 năm trước
mysqli_query
8
mysqli_query
9
mysqli_query
7Petrus.jvr ¶ ¶
Ẩn danh ¶
mysqli_num_rows
1
mysqli_num_rows
2
mysqli_query
74 năm trước ¶
Người nổi ¶
mysqli_num_rows
4
mysqli_num_rows
5
mysqli_num_rows
6
mysqli_num_rows
7
mysqli_num_rows
8
mysqli_num_rows
916 năm trước ¶
Đăng ký tại jdfoxmicro dot com
$query
0
$query
1
$query
2
$query
3
$query
4
mysqli_query
7
12 năm trước ¶
XA tại sagexa dot com ¶
$query
6
1 tháng trước ¶
14 năm trước
$query
7
$query
8
$query
9
mysqli_query
7họ tại Gmail dot com ¶
11 năm trước
$result_mode
1
$result_mode
2
Ẩn danh ¶ ¶
Người nổi ¶
$result_mode
4
$result_mode
5
$result_mode
6
$result_mode
7
$result_mode
816 năm trước ¶
Đăng ký tại jdfoxmicro dot com
$result_mode
9
MYSQLI_STORE_RESULT
0
mysqli_query
712 năm trước ¶
XA tại sagexa dot com ¶
MYSQLI_STORE_RESULT
2
MYSQLI_STORE_RESULT
3
MYSQLI_STORE_RESULT
41 tháng trước ¶
CEO tại L-i-e Dot Com ¶
MYSQLI_STORE_RESULT
5
MYSQLI_STORE_RESULT
6
MYSQLI_STORE_RESULT
7
MYSQLI_STORE_RESULT
8
MYSQLI_STORE_RESULT
9
mysqli_query
7jcwebb tại dicoe dot com ¶ ¶
Đăng ký tại jdfoxmicro dot com
$mysql
1
$mysql
2
mysqli_query
712 năm trước ¶
XA tại sagexa dot com ¶
$mysql
4
$mysql
5
$mysql
6
$mysql
7
mysqli_query
71 tháng trước ¶
Ẩn danh ¶
$mysql
9
if [mysqli_num_rows[$result] == 0] {
echo "email was not found";
} else {
echo "email was found";
}
00if [mysqli_num_rows[$result] == 0] {
echo "email was not found";
} else {
echo "email was found";
}
014 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";
}
02if [mysqli_num_rows[$result] == 0] {
echo "email was not found";
} else {
echo "email was found";
}
03if [mysqli_num_rows[$result] == 0] {
echo "email was not found";
} else {
echo "email was found";
}
04if [mysqli_num_rows[$result] == 0] {
echo "email was not found";
} else {
echo "email was found";
}
05if [mysqli_num_rows[$result] == 0] {
echo "email was not found";
} else {
echo "email was found";
}
06if [mysqli_num_rows[$result] == 0] {
echo "email was not found";
} else {
echo "email was found";
}
07mysqli_query
7Petrus.jvr ¶ ¶
Ẩn danh ¶
if [mysqli_num_rows[$result] == 0] {
echo "email was not found";
} else {
echo "email was found";
}
094 năm trước ¶
Ẩn danh ¶
if [mysqli_num_rows[$result] == 0] {
echo "email was not found";
} else {
echo "email was found";
}
10