A simple question about PHP

Source: Internet
Author: User
Asking for a simple PHP question
I want to get the number of rows affected by the database but $row how to get the number of rows that are affected on the implementation class side, and the novice can't afford to hurt, the bend won't turn.

Class userinfo{
Private $userName; attribute, user name
Private $passWord; Property
Private $userGrade; Properties, User Level
Private $row;
Private $userInfo; An array variable that stores the information returned by the database.

Public function __construct ($sql) {
Require_once ("db_config.php"); Contains configuration information.
$result = mysql_query ($sql, $conn); Execute Query statement
$this->userinfo = mysql_fetch_array ($result); Returning query results to an array
$row =mysql_num_rows ($result);
mysql_query ("Set names UTF8");
Mysql_close ($conn); To close a database connection
$this->getinfo (); Invokes the method that passes the information.
How to get information passed to a property
Private Function GetInfo () {

$this->username = $this->userinfo["UserName"];
$this->password = $this->userinfo["PassWord"];
$this->usergrade = $this->userinfo["Usergrade"];

Returns the public method for each property.

Public Function GetRow () {

return $this->row;
Public Function GetUserName () {

return $this->username;

Public Function GetPassword () {
return $this->password;

Public Function Getusergrade () {

$sql = "SELECT * from userinfo where username= ' sa '";
Require_once ("class_user.php");
$user = new UserInfo ($sql); Creates a user object.
Writing SQL
$row = $user->getrow ();
$username = $user->getusername (); Call method to get data separately
$password = $user->getpassword ();
$usergrade = $user->getusergrade ();

echo "Your name is". $username. "
"; Output data
echo "Your password is". $password. "

echo "Your grade is". $usergrade. "
echo "Your ROW is". $row. "

PHP Database SQL function

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.