<?php
function db_connect()
{
$result = new mysqli('localhost', 'root', '654321', 'smsprj');
//$result = new mysqli('localhost', 'root', '654321');
if (!$result)
{
throw new Exception('Could not connect to database server');
}
else
{
return $result;
}
}
?>
$conn = db_connect();
$sql = $conn->query("SELECT * FROM user");
if (!$sql)
{
echo ("wrong");
}
else
{
echo "<table>";
echo "<tr><td>userid</td><td>name</td><td>pssword</td><td>maxsmscount</td><td>maxuseday</td><td>leftday</td><td>leftsmscount</td></tr>";
while( $row = mysql_fetch_row($sql) )
{
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>$row[5]</td><td>$row[6]</td></tr>";
}
}
我的目的是将数据库中的所有用户信息显示出来
可这段程序老是报错,不知道什么原因
求大侠帮助,小弟不胜感激
mysql_fetch_row
------解决方案--------------------
db_connect 中是这样的
$result = new mysqli('localhost', 'root', '654321', 'smsprj');
所以要这样查询
$sql = $conn->query("SELECT * FROM user");
要这样读取
while( $row = $sql->fetch_row())