如何获取sql语句创建的所有输出?

时间:2014-02-10 17:04:10

标签: php sql

这是我的sql语句

SELECT TOWN_ID FROM TOWN WHERE CITY_ID = 1

输出为:4,5,6,7,67,887

在php中我的代码是这样的:

$temp = 1;
$sql = "SELECT TOWN_ID FROM TOWN WHERE CITY_ID = 1 = $temp";
$compiled = oci_parse($conn, $sql);
oci_execute($compiled);
$row = oci_fetch_array($compiled, OCI_ASSOC+OCI_RETURN_LOBS);
foreach ($row as $element ) 
{
  echo "\n".$element."\n";
}

我的输出只有4,如何获得其他输出?

1 个答案:

答案 0 :(得分:2)

manual返回查询中的下一行作为关联或数字数组

您需要在循环中调用此函数以获取所有记录:

while ($row = oci_fetch_array($compiled, OCI_ASSOC+OCI_RETURN_LOBS))
{
  foreach ($row as $element ) 
  {
    echo "\n".$element."\n";
  }
}