php MySqli : How can i rewrite fetch to fetch_assoc? LIKE CONCAT(php MySqli:如何将 fetch 重写为 fetch_assoc?像 CONCAT)
问题描述
你好,我使用bind_result"、LIKE CONCAT"...通过两个查询字符串达到全文搜索和分页.
Helo, I using "bind_result", "LIKE CONCAT" ... to reach full text search and pagination by two query string.
但是如何将 bind_result 方法更改为 fetch_assoc?
but how can I change bind_result methods to 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 文档示例:
From mysql documentation examples:
<?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
", $city, $myrow['district']);
}
?>
-----------编辑----------------------
-----------EDITED----------------------
请阅读此方法的用户注释:
Please read the user notes for this method:
http://php.net/manual/en/mysqli-stmt.get-result.php
它需要 mysqlnd 驱动程序...如果它没有安装在您的网站空间上,您将不得不使用 BIND_RESULT &获取!
It requires the mysqlnd driver... if it isn't installed on your webspace you will have to work with BIND_RESULT & FETCH!
http://www.php.net/manual/en/mysqli-stmt.bind-result.php
http://www.php.net/manual/en/mysqli-stmt.fetch.php
仅运行 MySQL 本机驱动程序
Function MySQL Native Driver Only
仅适用于 mysqlnd:http://www.php.net/manual/en/book.mysqlnd.php
Available only with mysqlnd: http://www.php.net/manual/en/book.mysqlnd.php
注意:mysqli_stmt::get_result() 仅适用于 PHP v5.3.0 或以上
Note: mysqli_stmt::get_result() is only available at PHP v5.3.0 or above
我要寻找另一种选择.
萨鲁多斯 ;)
这篇关于php MySqli:如何将 fetch 重写为 fetch_assoc?像 CONCAT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php MySqli:如何将 fetch 重写为 fetch_assoc?像 CONCAT


- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01