在我的本地计算机上托管后,一切正常。除非我搜索数据库中不可用的数据,否则我想收到错误消息“在此表上找不到结果”。请检查代码。
当我们搜索无效值时,不会弹出未找到结果错误。
获取.php
<?php
//fetch.php
$connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");
$output = '';
$query = '';
if(isset($_POST["query"]))
{
$search = str_replace(",", "|", $_POST["query"]);
$query = "
SELECT * FROM tbl_customer
WHERE CustomerName REGEXP '".$search."'
OR Address REGEXP '".$search."'
OR City REGEXP '".$search."'
OR PostalCode REGEXP '".$search."'
OR Country REGEXP '".$search."'
";
}
else
{
$query = "
SELECT * FROM tbl_customer ORDER BY CustomerID
";
}
$statement = $connect->prepare($query);
$statement->execute();
while($row = $statement->fetch(PDO::FETCH_ASSOC))
{
$data[] = $row;
}
echo json_encode($data);
?>
呼唤远方