$db=new mysqli('localhost','root','123','db');
    if(mysqli_connect_errno())
    {
exit;
    }
    $result=$db->query("select count(*) from users");
$db是 数据库连接的那个

解决方案 »

  1.   

    随便写了一下,不知道是不是你要的,记住,这是用了数据库操作的类。
    $sql = 'select count(*) AS total_records from users';
    $result = $db->query($sql);
    $row = $db->sql_fetchrow($result);
    $total_records =  $row['total_records'];//一共的记录数
      

  2.   

    貌似LZ不是很明白类的概念,此处的$db是一个包含数据库相关操作的类.通俗讲就像一个工具包,里面各种方法可以直接拿来调用,而不需你重新编写.所以你只需看明白3楼给你的例子,之后去你自己的类里找与之功能一样的方法即可.
      

  3.   

    $row = $db->sql_fetchrow($result);
    这行代码报错
    Call to undefined method mysqli::sql_fetchrow() 
      

  4.   

    呵呵,3楼只是给你一个参考,你要看明白他给你的写的方法,之后你要去你自己的DB类里找功能相同的方法拿来用.你直接用他的CODE当然不行了.sql_fetchrow()该方法在你的DB里可不是这个名.
      

  5.   

    相关参考:http://www.php.net/manual/zh/language.oop5.basic.php
      

  6.   

    谢谢 你们了可是 我还是不明白 我就是 想 练习一下 简单的登陆这个是 全部代码<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>上传文件</title>
    </head>
    <body>
    <?php
    $names=$_POST['username'];
    $pwd=$_POST['userpwd'];

    if($names && $pwd)
    {
        $db=new mysqli('localhost','root','123','db');
        if(mysqli_connect_errno())
        {
    exit;
        }
        $result=$db->query("select count(*) from users where username='$names' and userpwd='$pwd' ");
        这里 不知道该怎么 接值了
    }
    ?>
    <form action="login.php" method="post">
    账号:&nbsp;<input type="text" name="username"><br>
    密码:&nbsp;<input type="text" name="userpwd"><br>
    <input type="submit" value="提 交">&nbsp;&nbsp;&nbsp;<input type="reset" value="重 置">
    </form>
    </body>
    </html>刚才 你说的类 我没有太明白是什么意思 麻烦您了 能不能 说的详细些 谢谢了
      

  7.   

    我知道了用系统定义的 sql_fetchrow();方法就可以了 谢谢你们了