Home >Backend Development >PHP Tutorial > 请问关于pdo的prepare用法

请问关于pdo的prepare用法

WBOY
WBOYOriginal
2016-06-13 12:52:10989browse

请教关于pdo的prepare用法

本帖最后由 rainxies 于 2013-03-08 16:13:15 编辑 菜鸟求教,
类似这种写法,即同时查询多个SQL,用prepare该怎么取结果集啊?
<br />
$dbh = new PDO($dbConnString, $dbInfo['username'], $dbInfo['password']);<br />
$query = $dbh->query($queryString);<br />
$i = 0;<br />
foreach ($query as $query2) {<br />
  $queryReturn[$i] = $query2;<br />
  $i++;<br />
}<br />


------解决方案--------------------
本帖最后由 xuzuning 于 2013-03-11 09:05:47 编辑 如果你的sql指令就是#1的样子,那么对不起!
select FOUND_ROWS() 不会被发送到mysql去执行,因为他违反了一次只执行一条指令的安全约定

你可以将你的这两条指令写成存储过程
delimiter //<br />
CREATE PROCEDURE `test`()<br />
begin<br />
  select SQL_CALC_FOUND_ROWS * from table limit 1,10;<br />
  select FOUND_ROWS();<br />
end;<br />
// <br />
后这样执行
$queryString = 'call test();';<br />
$query = $dbh->query($queryString);<br />
do {<br />
  $rows = $query->fetchAll();<br />
  print_r($rows);<br />
}while($query->nextRowset());
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn