PHP uses the mysqli extension library to add, delete, modify, and query (object-oriented version), and mysqli object-oriented
The mysqli extension library is an improved version of the mysql extension library. It improves stability and efficiency based on the mysql extension library. The mysqli extension library has two sets of things, one is process-oriented mysqli, and the other is object-oriented mysqli. The operation method is basically the same as that of the mysql extension library. This time, we will first extract a tool class to operate mysql and the called class.
1. mysqli extended library operation database tool class
<? Php // database operation class DBUtil {private $ host = "localhost"; private $ username = "root"; private $ password = "123456"; private $ dbname = "student "; private $ conn; public function DBUtil () {$ this-> conn = new mysqli ($ this-> host, $ this-> username, $ this-> password, $ this-> dbname) or die ($ this-> conn-> connect_error);} // query public function query ($ SQL) {$ all = $ this-> conn-> query ($ SQL); return $ all;} // insert, modify, and delete public func Tion otherOperate ($ SQL) {if ($ this-> conn-> query ($ SQL) {if ($ this-> conn-> affected_rows> 0) {return "OK" ;}else {return "ERROOR" ;}} public function close () {$ this-> conn-> close () ;}}?>
2. The following is the code for calling the tool class.
<? Php require_once "MySQLUtil. php ";/* $ SQL =" select * from m_student "; $ util = new DBUtil (); $ result = $ util-> query ($ SQL ); while ($ row = $ result-> fetch_assoc () {echo "$ row [stuName]". "</br>" ;}$ result-> free (); $ util-> close (); */$ SQL = "update m_student set stuName = 'yang mi 'where id = 3"; $ util = new DBUtil (); $ result = $ util-> otherOperate ($ SQL); echo $ result; $ util-> close ();?>
Read more: www.manongjc.com/article/1206.html