Home >Backend Development >PHP Tutorial >一个PHP比较简单的有关问题

一个PHP比较简单的有关问题

WBOY
WBOYOriginal
2016-06-13 11:10:16915browse

求助一个PHP比较简单的问题
我想获取数据库受影响的行数 可是$row怎么在实现类这边获取返回影响的行数呢,新手伤不起,这个弯不会转了

<br /><? <br />	// class_user.php <br />class UserInfo{ <br />   private $userName;  //属性,用户名 <br />   private $passWord;  //属性, <br />   private $userGrade; //属性,用户级别<br />   private $row; <br />   private $userInfo; //存储数据库返回信息的数组变量. <br />	  <br />	    public function __construct($sql){ <br />	        require_once("db_config.php"); //包含配置信息. <br />	        $result= mysql_query($sql, $conn); // 执行查询语句 <br />	        $this->userInfo = mysql_fetch_array($result); //返回查询结果到数组<br />			$row=mysql_num_rows($result); <br />			mysql_query("set names UTF8");<br />	        mysql_close($conn); //关闭数据库连接 <br />	      $this->getInfo(); //调用传递信息的方法.	 <br />	    } <br />	    // 获取信息传递给属性的方法 <br />	    private function getInfo(){ <br />		 <br />	        $this->userName = $this->userInfo["username"]; <br />	        $this->passWord = $this->userInfo["password"];	<br />	        $this->userGrade = $this->userInfo["userGrade"]; <br />	    } <br />	      <br />	    //返回每个属性的public 方法. <br /><br />   public function getRow(){ <br />		<br />	        return $this->row; <br />	    } <br />	    public function getUserName(){ <br />		<br />	        return $this->userName; <br />	    } <br />	      <br />	    public function getPassword(){ <br />	        return $this->passWord; <br />	    } <br />	 <br />	      <br />	    public function getUserGrade(){ <br />	        return$this->userGrade; <br />	    } <br />		<br />		<br />	} <br />		$sql= "select * from userinfo where username='sa' ";<br />	require_once("class_user.php");   <br />	$user= new UserInfo($sql); //创建一个user对象. <br />	    //书写sql<br />	$row= $user->getRow(); <br />	$username= $user->getUserName(); //分别调用方法取得数据 <br />	$password= $user->getPassword(); <br />	$usergrade= $user->getUserGrade(); <br />	  <br />	echo"your name is ".$username."<br>";  //输出数据 <br />	echo"your password is ".$password."<br>"; <br /><br />	echo"your grade is ".$usergrade."<br>"; <br />	echo"your ROW is ".$row."<br>"; <br />	?><br /><br />

php 数据库 sql function
------解决方案--------------------
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn