A simple PHP question

Source: Internet
Author: User
For a simple PHP problem, I want to obtain the number of affected rows in the database & nbsp; but how does $ row obtain the number of rows affected by the returned results in the implementation class? this is not a problem for beginners, this bend won't be changed & lt ;? & Nbsp; class_user.php & nbsp; class & nbsp; UserInfo {& nbsp; private & nbsp; $ user asks for a simple PHP question
I want to obtain the number of affected rows in the database, but how does $ row obtain the number of rows affected by the returned results in the implementation class? the new user cannot afford to hurt, and this bend won't go wrong.

// Class_user.php
Class UserInfo {
Private $ userName; // attribute, user name
Private $ passWord; // attribute,
Private $ userGrade; // attribute, user level
Private $ row;
Private $ userInfo; // array variable that stores the information returned by the database.

Public function _ construct ($ SQL ){
Require_once ("db_config.php"); // contains the configuration information.
$ Result = mysql_query ($ SQL, $ conn); // execute the query statement
$ This-> userInfo = mysql_fetch_array ($ result); // return the query result to the array.
$ Row = mysql_num_rows ($ result );
Mysql_query ("set names UTF8 ");
Mysql_close ($ conn); // Close the database connection
$ This-> getInfo (); // call the method for passing information.
}
// Obtain the method for passing information to the attribute
Private function getInfo (){

$ This-> userName = $ this-> userInfo ["username"];
$ This-> passWord = $ this-> userInfo ["password"];
$ This-> userGrade = $ this-> userInfo ["userGrade"];
}

// Return the public method of each attribute.

Public function getRow (){

Return $ this-> row;
}
Public function getUserName (){

Return $ this-> userName;
}

Public function getPassword (){
Return $ this-> passWord;
}


Public function getUserGrade (){
Return $ this-> userGrade;
}


}
$ SQL = "select * from userinfo where username = 'sa '";
Require_once ("class_user.php ");
$ User = new UserInfo ($ SQL); // Create a user object.
// Write SQL
$ Row = $ user-> getRow ();
$ Username = $ user-> getUserName (); // call methods to obtain data respectively
$ 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


------ Solution --------------------

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.