请教关于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 />
Copy after login
------解决方案--------------------本帖最后由 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 />
Copy after login
后这样执行
$queryString = 'call test();';<br />
$query = $dbh->query($queryString);<br />
do {<br />
$rows = $query->fetchAll();<br />
print_r($rows);<br />
}while($query->nextRowset());
Copy after login
Statement of this Website
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31