标签:php mysqli pagination prepare
直升机,
我使用“bind_result”,“LIKE CONCAT”…通过两个查询字符串达到全文搜索和分页.
但是如何将bind_result方法更改为fetch_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']);
}
?>
———– EDITED ———————-
请阅读此方法的用户说明:
http://php.net/manual/en/mysqli-stmt.get-result.php
它需要mysqlnd驱动程序……如果它没有安装在你的网站空间上,你将不得不使用BIND_RESULT&取!
http://www.php.net/manual/en/mysqli-stmt.bind-result.php
http://www.php.net/manual/en/mysqli-stmt.fetch.php
仅限MySQL本机驱动程序
仅适用于mysqlnd:http://www.php.net/manual/en/book.mysqlnd.php
注意:mysqli_stmt :: get_result()仅适用于PHP v5.3.0或更高版本
我要去寻找另一种选择.
Saludos;)
标签:php,mysqli,pagination,prepare 来源: https://codeday.me/bug/20191008/1873747.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。