gpt4 book ai didi

PHP STMT MySQL 查询在设置为等于时返回 LIKE 结果

转载 作者:行者123 更新时间:2023-11-28 23:42:39 25 4
gpt4 key购买 nike

也许我遗漏了一些明显的东西,但我没有从这个查询中得到我期望的结果。我从非严格的 LIKE 查询中得到了我期望的结果。

public function get_product_list_by_title($title){
$result = ARRAY();
$stmt = $this->cn->prepare("SELECT `id`, `name`, `price`, `comments` FROM Products WHERE `name` = ?");
$stmt->bind_param("i", $title);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result(
$id,
$name,
$price,
$notes
);
while ($stmt->fetch()) {
$result[] = Array(
"id" => $id,
"name" => $name,
"price" => $price,
"notes" => $notes
);
}
$stmt->free_result();
$stmt->close();
return $result;
}

例如,如果我搜索“3”,我会得到所有以 3 开头的项目(可能更多 - 它是一个小数据集)

有什么想法吗?

最佳答案

根据您的评论,$title 是一个字符串,name 列是一个 VARCHAR。但是当你像这样绑定(bind) $title

$stmt->bind_param("i", $title);

您强行将其转换为整数。将该行更改为

$stmt->bind_param("s", $title);

bind_param中,"i"表示参数作为整数传递,而"s"将其作为字符串处理。

关于PHP STMT MySQL 查询在设置为等于时返回 LIKE 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34095844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com