此代码在 SQL Server 2000 中经过测试,在其他版本(如 2005 或 2008)中未经测试。尽管如此,它不适用于 MySQL,因为不存在 "sysindexes" 表。
$cnx = odbc_connect("dbSQLEmpresa","Admin","123");
if ($cnx)
{
$rs = odbc_exec($cnx, "SELECT * FROM alumnos");
$f = odbc_num_fields($rs);
$r = odbc_num_rows($rs);
$r = LFRJ_odbc_num_rows($cnx,"alumnos");
echo "<table border = '1'>";
for ($i = 1; $i <= $f; $i++)
{
$n = odbc_field_name($rs, $i);
echo "<th>", $n, "</th>";
}
while(odbc_fetch_row($rs))
{
echo "<tr>";
for ($i = 1; $i <= $f; $i++)
{
$d = odbc_result($rs, $i);
echo "<td>", $d, "</td>";
}
echo "</tr>";
}
echo "<tr><td colspan = '" . $f . "'>字段(" . $f . ") 记录(" . $r . ")</td></tr>";
echo "</table>";
}
odbc_close($cnx);
function LFRJ_odbc_num_rows($cnx,$Tabla)
{
$rs = odbc_exec($cnx, "SELECT rows FROM sysindexes WHERE id = OBJECT_ID('" . $Tabla . "') AND indid < 2;");
return odbc_result($rs, 1);
}