这是我自己写的mysql类里面的一段 function select_db ($sql_string)
{
unset($this->records);
@mysql_free_result($this->result);
$this->result=@mysql_query($sql_string,$this->db);
$i=1;
while($tempRows=@mysql_fetch_array($this->result, MYSQL_ASSOC))
{
for ($j=0;$j<count($tempRows);$j++) {
$tempKeyName = mysql_field_name($this->result, $j);
$this->records["$tempKeyName"][$i] = $tempRows["$tempKeyName"];
}
$i++;
}
return $this->records;
}
{
unset($this->records);
@mysql_free_result($this->result);
$this->result=@mysql_query($sql_string,$this->db);
$i=1;
while($tempRows=@mysql_fetch_array($this->result, MYSQL_ASSOC))
{
for ($j=0;$j<count($tempRows);$j++) {
$tempKeyName = mysql_field_name($this->result, $j);
$this->records["$tempKeyName"][$i] = $tempRows["$tempKeyName"];
}
$i++;
}
return $this->records;
}
下面这个输出array[记录序号][字段名]
序号都是从1开始,不是从0开始,可以自己选择 function select_db ($sql_string)
{
@mysql_free_result($this->result);
$this->result=@mysql_query($sql_string,$this->db);
$i=1;
while($tempRows=@mysql_fetch_array($this->result, MYSQL_ASSOC))
{
$this->records[$i] = $tempRows;
$i++;
}
return $this->records;
}
unset($this->records);
加在同前面第一段相同位置,不加的话多次查询输出的数组会出错的