Hướng dẫn how can i see mysqli errors? - làm thế nào tôi có thể thấy lỗi mysqli?

❮ Php mysqli tham khảo

Ví dụ - Phong cách định hướng đối tượng

Trả về mô tả lỗi cuối cùng cho cuộc gọi chức năng gần đây nhất, nếu có:

$mysqli = new mysqli("localhost","my_user","my_password","my_db");

if ($ mysqli -> connect_errno) {& nbsp; Echo "Không thể kết nối với MySQL:". $ mysqli -> Connect_error; & nbsp; lối ra(); }
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
}

// thực hiện truy vấn, kiểm tra lỗi (! $ Mysqli -> truy vấn ("chèn vào giá trị của người (firstName) ('glenn')")) {& nbsp; echo ("Mô tả lỗi:". $ mysqli -> lỗi); }
if (!$mysqli -> query("INSERT INTO Persons (FirstName) VALUES ('Glenn')")) {
  echo("Error description: " . $mysqli -> error);
}

$ mysqli -> đóng ();?>
?>


Nhìn vào ví dụ về phong cách thủ tục ở phía dưới.


Định nghĩa và cách sử dụng

Hàm lỗi / mysqli_error () trả về mô tả lỗi cuối cùng cho cuộc gọi chức năng gần đây nhất, nếu có.


Cú pháp

Phong cách định hướng đối tượng:

Phong cách thủ tục:

Giá trị tham số

Tham sốSự mô tả
sự liên quanYêu cầu. Chỉ định kết nối MySQL để sử dụng

Chi tiết kỹ thuật

Giá trị trở lại:Trả về một chuỗi với mô tả lỗi. "" Nếu không xảy ra lỗi
Phiên bản PHP:5+

Ví dụ - Phong cách định hướng thủ tục

Trả về mô tả lỗi cuối cùng cho cuộc gọi chức năng gần đây nhất, nếu có:

$con=mysqli_connect("localhost","my_user","my_password","my_db");

if ($ mysqli -> connect_errno) {& nbsp; Echo "Không thể kết nối với MySQL:". $ mysqli -> Connect_error; & nbsp; lối ra(); }
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  exit();
}

// thực hiện truy vấn, kiểm tra lỗi (! $ Mysqli -> truy vấn ("chèn vào giá trị của người (firstName) ('glenn')")) {& nbsp; echo ("Mô tả lỗi:". $ mysqli -> lỗi); }
if (!mysqli_query($con,"INSERT INTO Persons (FirstName) VALUES ('Glenn')")) {
  echo("Error description: " . mysqli_error($con));
}

$ mysqli -> đóng ();?>
?>



❮ Php mysqli tham khảo


mysqli_error

(Php 5, Php 7, Php 8)

MySQLI :: $ ERROR - mysqli_error - Trả về mô tả chuỗi của lỗi cuối cùng -- mysqli_errorReturns a string description of the last error

Sự mô tả

Phong cách hướng đối tượng

Phong cách thủ tục

mysqli_error (mysqli $mysql): chuỗi(mysqli $mysql): string

Trả về giá trị

Một chuỗi mô tả lỗi. Một chuỗi trống nếu không xảy ra lỗi.

Ví dụ

Ví dụ #1 $ mysqli-> Ví dụ về lỗi

Phong cách hướng đố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();
}

if (!

$mysqli->query("SET a=1")) {
    
printf("Error message: %s\n"$mysqli->error);
}
/* close connection */
$mysqli->close();
?>

Phong cách thủ tục

$link mysqli_connect("localhost""my_user""my_password""world");/* check connection */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

if (!

mysqli_query($link"SET a=1")) {
    
printf("Error message: %s\n"mysqli_error($link));
}
/* close connection */
mysqli_close($link);
?>

mysqli_error (mysqli $mysql): chuỗi

Error message: Unknown system variable 'a'

Trả về giá trị

  • Một chuỗi mô tả lỗi. Một chuỗi trống nếu không xảy ra lỗi.
  • Ví dụ
  • Ví dụ #1 $ mysqli-> Ví dụ về lỗi
  • Các ví dụ trên sẽ xuất ra:

Thông tin tại Saunderswebsolutions dot com

16 năm trước

The mysqli_sql_exception class is not available to PHP 5.05

I used this code to catch errors
$query = "SELECT XXname FROM customer_table ";
$res = $mysqli->query($query);

$mysql0

$mysql1

SE (at) Brainbits (DOT) NET ¶

16 năm trước

$mysql2

$mysql3

$mysql4

$mysql5

$mysql6

$mysql7

SE (at) Brainbits (DOT) NET ¶

callforeach tại gmail dot com

$mysql8

$mysql9

$mysqli = new mysqli("localhost""my_user""my_password""world");/* check connection */
if ($mysqli->connect_errno) {
    
printf("Connect failed: %s\n"$mysqli->connect_error);
    exit();
}
0

$mysqli = new mysqli("localhost""my_user""my_password""world");/* check connection */
if ($mysqli->connect_errno) {
    
printf("Connect failed: %s\n"$mysqli->connect_error);
    exit();
}
1

$mysqli = new mysqli("localhost""my_user""my_password""world");/* check connection */
if ($mysqli->connect_errno) {
    
printf("Connect failed: %s\n"$mysqli->connect_error);
    exit();
}
2

7 năm trước

Abderrahmanekaddour dot aissat tại gmail dot com ¶

$mysqli = new mysqli("localhost""my_user""my_password""world");/* check connection */
if ($mysqli->connect_errno) {
    
printf("Connect failed: %s\n"$mysqli->connect_error);
    exit();
}
3

1 tháng trước

asmith26 tại Littlesvr dot ca ¶

$mysqli = new mysqli("localhost""my_user""my_password""world");/* check connection */
if ($mysqli->connect_errno) {
    
printf("Connect failed: %s\n"$mysqli->connect_error);
    exit();
}
4

$mysqli = new mysqli("localhost""my_user""my_password""world");/* check connection */
if ($mysqli->connect_errno) {
    
printf("Connect failed: %s\n"$mysqli->connect_error);
    exit();
}
5

$mysqli = new mysqli("localhost""my_user""my_password""world");/* check connection */
if ($mysqli->connect_errno) {
    
printf("Connect failed: %s\n"$mysqli->connect_error);
    exit();
}
6

$mysql7

Thông tin tại Saunderswebsolutions dot com

16 năm trước

$mysqli = new mysqli("localhost""my_user""my_password""world");/* check connection */
if ($mysqli->connect_errno) {
    
printf("Connect failed: %s\n"$mysqli->connect_error);
    exit();
}
8

SE (at) Brainbits (DOT) NET ¶

callforeach tại gmail dot com

$mysqli = new mysqli("localhost""my_user""my_password""world");/* check connection */
if ($mysqli->connect_errno) {
    
printf("Connect failed: %s\n"$mysqli->connect_error);
    exit();
}
9

Làm cách nào để tìm lỗi truy vấn mysqli?

Hàm lỗi / mysqli_error () trả về mô tả lỗi cuối cùng cho cuộc gọi chức năng gần đây nhất, nếu có.error / mysqli_error() function returns the last error description for the most recent function call, if any.

Làm thế nào hiển thị thông báo lỗi MySQL trong PHP?

Thay vào đó, hãy sử dụng mysql_error () để truy xuất văn bản lỗi.Lưu ý rằng hàm này chỉ trả về văn bản lỗi từ hàm mySQL được thực thi gần đây nhất (không bao gồm mysql_error () và mysql_errno ()), vì vậy nếu bạn muốn sử dụng nó, hãy đảm bảo bạn kiểm tra giá trị trước khi gọi hàm MySQL khác.use mysql_error() to retrieve the error text. Note that this function only returns the error text from the most recently executed MySQL function (not including mysql_error() and mysql_errno()), so if you want to use it, make sure you check the value before calling another MySQL function.

Lỗi MySQLI là gì?

Hàm php mysqli_error () trả về giá trị chuỗi biểu thị mô tả lỗi từ lệnh gọi hàm mySQLI cuối cùng.Nếu không có lỗi, chức năng này sẽ trả về một chuỗi trống.returns an string value representing the description of the error from the last MySQLi function call. If there are no errors this function returns an empty string.

Làm thế nào để tôi biết nếu mysqli truy vấn thành công?

Làm thế nào để kiểm tra xem một truy vấn MySQLI có thành công trong câu trả lời mã PHP hay không..
Hàm lỗi / mysqli_error () trả về mô tả lỗi cuối cùng cho cuộc gọi chức năng gần đây nhất, nếu có.
// peform một truy vấn ..
$ query = "Chọn`*`từ người dùng" ;.
$ results = mysqli_query ($ databaseConnection, $ query) ;.
if (mysqli_num_rows ($ results) == 0) {.
// Truy vấn trả về 0 hàng !.
} khác {.
// Truy vấn trả về ít nhất một hàng ..