Trong PHP, tôi đang cố gắng thực hiện truy vấn MySql dài phụ thuộc vào đầu vào của người dùng. Tuy nhiên, câu hỏi của tôi không thành công với thông báo sau,làm thế nào để hiển thị lỗi MySql trong php
"Query Failed".
Thật sự tôi đã in thông điệp này bất cứ khi nào truy vấn thất bại nhưng tôi đang gặp khó khăn tìm kiếm các lý do đằng sau sự thất bại này. Thật không may, tôi không thể tìm thấy nó vì lỗi không được chỉ định trên trang web. Câu hỏi của tôi là, có cách nào để hiển thị thông báo lỗi gây ra lỗi trên trang web không. Cảm ơn bạn.
Dưới đây là mã của tôi,
$from= "Findings";
$where="";
if($service!= null)
{
$from = $from . ", ServiceType_Lookup";
$where= "Findings.ServiceType_ID= ServiceType_Lookup.ServiceType_ID AND ServiceType_Name= ". $service;
if($keyword!= null)
$where= $where . " AND ";
}
if($keyword != null)
{
$where= $where . "Finding_ID LIKE '%$keyword%' OR
ServiceType_ID LIKE '%$keyword%' OR
Title LIKE '%$keyword%' OR
RootCause_ID LIKE '%$keyword%' OR
RiskRating_ID LIKE '%$keyword%' OR
Impact_ID LIKE '%$keyword%' OR
Efforts_ID LIKE '%$keyword%' OR
Likelihood_ID LIKE '%$keyword%' OR
Finding LIKE '%$keyword%' OR
Implication LIKE '%$keyword%' OR
Recommendation LIKE '%$keyword%' OR
Report_ID LIKE '%$keyword%'";
}
$query = "SELECT Finding_ID,
ServiceType_ID,
Title,
RootCause_ID,
RiskRating_ID,
Impact_ID,
Efforts_ID,
Likelihood_ID,
Finding,
Implication,
Recommendation,
Report_ID FROM ".$from . " WHERE " . $where;
echo "wala 2eshiq";
$this->result = $this->db_link->query($query);
if (!$this->result) {
printf("Query failed: %s\n", mysqli_connect_error());
exit;
}
$r = mysqli_query($this->db_link, $query);
if($r==false)
printf("error: %s\n", mysqli_errno($this->db_link));
Bạn chỉ có thể sử dụng: '$ this-> db_link-> error' để nhận thông báo lỗi cuối cùng. Đối với tất cả các lỗi sử dụng '$ this-> db_link-> error_list'. – hakre