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 --------------------