gpt4 book ai didi

php - get_result() 在本地主机上工作,但不在实时服务器上工作

转载 作者:行者123 更新时间:2023-11-29 09:32:28 24 4
gpt4 key购买 nike

我正在编写一段代码,用于通过用户传递的查询实时搜索记录。编写的代码如下:

if(isset($_REQUEST["term"])){
$sql = "SELECT * FROM students WHERE rollno LIKE ?";
if($stmt = $conn->prepare($sql)){
$stmt->bind_param("s", $param_term);
$param_term = $_REQUEST["term"] . '%';
if($stmt->execute()){
$result = $stmt->get_result(); // error on this line
if($result->num_rows > 0){
// Fetch result rows as an associative array
while($row = $result->fetch_array(MYSQLI_ASSOC)){
$rollno = $row['rollno'];
$name = $row['name'];
$image = $row['image'];
echo $rollno." ".$name." ".$image;
}
}
}
}
}

代码在本地服务器上运行良好。但相同的代码不适用于具有相同数据库的实时服务器。我收到错误 Fatal error: Call to undefined method mysqli_stmt::get_result() in/home/u687417727/public_html/digiclass/panel/backend-search.php on line 25
在我输入一些查询之后。我已经用注释显示了代码中的错误。可能是什么问题呢?请帮助。尝试长时间评估它。

最佳答案

您有两个选择,要么在您的服务器上的php_info中安装mysqlnd How to enable mysqlnd for php?

或者为此编写自己的函数

 function get_result($stmt){
$stmt->execute(); //Execute query
$stmt->store_result(); //Store the results
$num_rows = $stmt->num_rows; //Get the number of results
$results = NULL;
if($num_rows > 0){
//Get metadata about the results
$meta = $stmt->result_metadata();
//Here we get all the column/field names and create the binding code
$bind_code = "return mysqli_stmt_bind_result(\$stmt, ";
while($_field = $meta->fetch_field()){
$bind_code .= "\$row[\"".$_field->name."\"], ";
}
//Replace trailing ", " with ");"
$bind_code = substr_replace($bind_code,");", -2);
//Run the code, if it doesn't work return NULL
if(!eval($bind_code)) {
$stmt->close();
return NULL;
}
//This is where we create the object and add it to our final result array
for($i=0;$i<$num_rows;$i++){
//Gets the row by index
$stmt->data_seek($i);
//Update bound variables used in $bind_code with new row values
$stmt->fetch();
foreach($row as $key=>$value){
//Create array using the column/field name as the index
$_result[$key] = $value;
}
//Cast $_result to object and append to our final results
$results[$i] = (object)$_result;
}
}
$stmt->close();
return $results;
}

关于php - get_result() 在本地主机上工作,但不在实时服务器上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58393464/

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