当前位置:编程学习 > php >>

php帮我看一下$num = $conne->getRowsNum($sql); $conne->close_rst();这两条看不懂啊

<?php session_start(); include_once 'conn/conn.php'; //执行连接数据库的操作 $name = addslashes($_POST['name']); //获取用户名 $pwd = $_POST['pwd']; //获取密码 if(!empty($name) and !empty($pwd)){ $sql = "select * from tb_member where name = '".$name."' and password = '".$pwd."'"; $num = $conne->getRowsNum($sql); //返回查询结果 $conne->close_rst(); //关闭数据库 if($num == 0 or $num == ''){ //如果不正确 echo "<script>alert('用户名和密码不正确!'); window.location.href='index.php';</script>"; }else{ //如果正确,则将登录用户名数据存储到Cookie中 $_SESSION[name]=$name; echo "<script>alert('登录成功!'); window.location.href='default.php';</script>"; } } ?>
答案:php帮我看一下$num = $conne->getRowsNum($sql); $conne->close_rst();这两条看不懂啊
这是一个自定义的数据库类:

$host  $name  $pwd  $dBase  $conn private  $msg  $fields $fieldsNum $filesArray $rowsArray  都是这个类的成员变量   function __construct是构造函数    剩余其它的都是成员函数了

随便拿个举例吧:

取得多条记录这个:

function getRowsArray($sql){ 
$this-> mysql_query_rst($sql); 
while($row = @mysql_fetch_array($this->result,MYSQL_ASSOC)) { 
    $this->rowsArray[] = $row; 
  } 
return $this->rowsArray; 
} 


其中:$sql 变量代表你的mysql查询语句

$this-> mysql_query_rst($sql);  //这句用于向数据库查询多天记录

while($row = @mysql_fetch_array($this->result,MYSQL_ASSOC)) 
{ 
    $this->rowsArray[] = $row; 
}    
//while语句把查到的多条结果全部保存在 $this->rowsArray[] 数组中


return $this->rowsArray;  //这句返回一个包涵多条查询记录的数组

所以调用getRowsArray($sql)函数就是查询数据库的多条记录并放在数组里面供你使用的


你要真想把这数据库类完全看懂,你就必须熟悉这些基本的php操作mysql的数据库的函数 和 明白面向对象编程是怎么一回事,看看php类的创建和使用方法吧。

你的这段代码我没说错的话,应该是明日科技出版的php教材配套源码里面的。
其他:conn.php中定义了数据库类,定义了CRDU操作方法,getRowsNum(),close_rst() 就类中的两个方法,$conne 实例化对象;
conn.php有这样的块 class object {... }

$conne = new object();调用类中方法,先实例化对像
$conne->getRowsNum() ;
$conne->close_rst()  ; $conne是定义的类
 $conne->getRowsNum($sql); 调用类的方法
下面也是这样 调用  $conne 对象的 两个事件 getRowsNum();,close_rst();
getRowsNum();,事件返回 执行select * from tb_member where name = '".$name."' and password = '".$pwd 这段SQL语句的结果条数,close_rst();
事件断开数据库连接 

上一个:unix下如何发布php网页
下一个:PHP应该怎么学?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,