欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

请教个问题 mysql记录集不支持movenext方法吗

程序员文章站 2024-01-30 17:28:16
...
function GetTags($device)
{
$sql = "select tagname from TagList where device='$device'";
$rs = mysql_query($sql);
while(! $rs->eof) //将记录集存储到二维数组
{
$tags[] = array('tagname'=>$rs->fields['tagname']->value);
$rs->MoveNext();
}
return $tags;
mysql_free_result($rs); //关闭数据集
}
为什么我在php查询mysql数据库,操作记录集时使用movenext方法一直报错no-object?难道mysql记录集不支持这个方法吗,那该如何实现?另外循环里的数组$tags在循环外能正确返回吗?
我想将记录集存储到数组,并返回这个数组,请高手给看看!


回复讨论(解决方案)

是的,不支持

while($row = mysql_fetch_assoc($rs))   //将记录集存储到二维数组{     $tags[] = $row;}

那return $tags;
这条语句能返回值吗?

当然能!
你遇到了什么问题?

$tags只有一条记录,很奇怪,如果查询多个字段,咋存到二维数组?存储后效果$tags('tagname','device','unit'),能够$tags[$i][tagname]这样引用,这该咋存啊?mysql这块和Oracle不太一样,请帮帮忙,谢谢!
$sql = "select tagname,device,unit from TagList where device='$device'";
$rs = mysql_query($sql);
.......

奇怪了,经

while($row = mysql_fetch_assoc($rs))   //将记录集存储到二维数组{     $tags[] = $row;}

后 $tags 不就是二维数组了吗?