无法使PDO倒带与PDO :: FETCH_ORI_ABS一起使用 [英] Can't make PDO rewind work with PDO::FETCH_ORI_ABS
问题描述
我需要对变量进行几次扫描,并且使用mysql_data_seek没有问题.现在,我正在尝试PDO,但现在无法正常工作了.
I need to scan several times the variable and using mysql_data_seek I had no problems. Now that I'm trying PDO I can't make it work.
我这样使用它:
while($rowAssistant = $rowSetAssistantsProject->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, 0)){
但它并不会进入一段时间(我想是因为它在$ rowSetAssistantsProject的结尾)
but it doesn't go inside the while (I guess because it is on the end of $rowSetAssistantsProject)
推荐答案
PDO中没有mysql_data_seek
,并且当前的mysql-php连接不支持游标.相反,您应该做的是将所有数据拉到一个数组中并对其进行迭代.
There is no mysql_data_seek
in PDO and the current mysql-php connections do not support cursors. What you should do instead is pull all your data into an array and iterate over that.
$rows = $rowSetAssistantsProject->fetchAll(PDO::FETCH_ASSOC);
foreach($rows as $row) {
// Process rows
}
// Where you would have reset mysql_data_seek back to 0 if it existed
foreach($rows as $row) {
// More row processing
}
一旦数据以数组形式出现,您就可以使用reset
函数将光标放在数组上,例如这篇文章做.但是上面的代码是自从我转移到PDO以来必须要做的.希望有帮助.
Once your data is in array form you can place a cursor on the array using the reset
function like this post does. But the code above is what I have had to do since I moved to PDO. Hope that helps.
这篇关于无法使PDO倒带与PDO :: FETCH_ORI_ABS一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!