gpt4 book ai didi

php - Mysqli准备的语句选择不起作用,不返回错误

转载 作者:行者123 更新时间:2023-11-30 00:02:49 26 4
gpt4 key购买 nike

我正在尝试将一些代码从常规mysqli选择查询切换到更安全的mysqli准备好的语句,但是无论我在过去几个小时中尝试了哪种方法,它都无法正常工作,在此代码中我有没有遗漏的东西吗?

function getProjectSites($selected){

global $db;

$result = $db->prepare("SELECT DISTINCT site_location, id FROM projects WHERE project_name_id = ? ORDER BY site_location");

$result->bind_param('s', $selected);


return $result->execute();

}

$stmt = getProjectSites($selected);
$stmt->store_result();

/* Get the result */
$res = $stmt->get_result();

while ($row = $res->fetch_assoc()) {

//no rows are output

最佳答案

你可以试试这个->

function getProjectSites($selected){
global $db;
$result = $db->prepare("SELECT DISTINCT site_location, id FROM projects WHERE project_name_id = ? ORDER BY site_location");
$result->bind_param('s', $selected);
return $result->execute();
}
$stmt = getProjectSites($selected);
$stmt->store_result();
// Fetch a record. Bind the result to a variable called 'value' and fetch.
$stmt->bind_result($value) ;
$res = $stmt->fetch() ;
if($res)
{
//This is just an example you do your code here
echo "data length is " . strlen($value);
}

关于php - Mysqli准备的语句选择不起作用,不返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24878221/

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