php MySqli:我如何重写fetch以获取_assoc?像海螺

php MySqli:我如何重写fetch以获取_assoc?像海螺,php,mysqli,pagination,prepare,Php,Mysqli,Pagination,Prepare,你好, 我使用“绑定结果”,“像CONCAT”。。。通过两个查询字符串实现全文搜索和分页 但是如何更改bind\u result方法以获取\u assoc <?php $mysqli = new mysqli("localhost", "", "", "test"); $query_string="hello"; //keywords $sqltxt="SELECT * FROM `table` WHERE text1 LIKE CONCAT('%', ?, '%')"; //f

你好, 我使用“绑定结果”,“像CONCAT”。。。通过两个查询字符串实现全文搜索和分页

但是如何更改bind\u result方法以获取\u assoc

<?php
$mysqli = new mysqli("localhost", "", "", "test");


$query_string="hello"; //keywords

$sqltxt="SELECT * FROM `table` WHERE text1 LIKE CONCAT('%', ?, '%')";


//first query : for get the total number of data
$stmt = $mysqli->prepare($sqltxt);
$stmt->bind_param("s",$query_string);
$stmt->execute();
$stmt->store_result();
$total =$stmt->num_rows;

$lastpage = ceil($total/20);//obtain the last page

$page=$_GET["page"];
$startpoint = ($page * 20) - 20;

//second query : for get the true data
$stmt = $mysqli->prepare($sqltxt ." LIMIT {$startpoint}, 20");
$stmt->bind_param("s",$query_string);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id,$title,$tel); //<= hits!! I want to using fetch_assoc methods

while($stmt->fetch()){ //<= hits!! I want to using fetch_assoc methods


echo $id;
echo $atitle;
echo $tel;

}


?>

mysql文档示例中的

<?php

// ... document's example code:

/* bind parameters for markers */
$stmt->bind_param("s", $city);

/* execute query */
$stmt->execute();

/* instead of bind_result: */
$result = $stmt->get_result(); //with get_result ;)

/* now you can fetch the results into an array - NICE */
while ($myrow = $result->fetch_assoc()) { //now you can use fetch_assoc

    // use your $myrow array as you would with any other fetch
    printf("%s is in district %s\n", $city, $myrow['district']);

}
?>

调用未定义的方法mysqli_stmt::get_result()