Link database encapsulation class, link database Encapsulation
<? Phpclass DBDA {public $ host = "localhost"; public $ uid = "root"; public $ pwd = "root"; public $ dbname = "db_0808 "; /*** return the execution result for an SQL statement * @ param string $ the SQL statement specified by the SQL user * @ param int $ type, 0 indicates addition, deletion, modification, and 1 indicates Query * @ return. If it is a Query, two-dimensional array is returned. If it is an addition, deletion, modification, or false */function Query ($ SQL, $ type = 1) {// create a connection object $ db = new MySQLi ($ this-> host, $ this-> uid, $ this-> pwd, $ this-> dbname); // execute the SQL statement $ reslut = $ db-> query ($ SQL );
if(!$reslut){
die($db->error);
}
// Obtain data from the result set object if ($ type = 1) {return $ reslut-> fetch_all () ;} else {return $ reslut ;}} /*** return an associated two-dimensional array for an SQL statement * @ param string $ the SQL statement specified by the SQL user * @ param int $ type, 0 indicates addition, deletion, modification, and 1 indicates query * @ return. If query is used, a two-dimensional array is returned. If it is added, deletion, modification, or false */function GuanQuery ($ SQL, $ type = 1) {// create a connection object $ db = new MySQLi ($ this-> host, $ this-> uid, $ this-> pwd, $ this-> dbname); // execute the SQL statement $ reslut = $ db-> query ($ SQL); // obtain the data if ($ type = 1) {$ attr = array (); while ($ a = $ reslut-> fetch_assoc () {$ attr [] = $ a;} return $ attr ;} else {return $ reslut;}/*** to an SQL statement, returns the string * @ param string $ the SQL statement specified by the SQL user * @ param int $ type. The value 0 indicates addition, deletion, and modification, 1 indicates query * @ return: return the query result. If it is a query return string, if it is an addition, deletion, modification, return true or false */function StrQuery ($ SQL, $ type = 1) {// create a connection object $ db = new MySQLi ($ this-> host, $ this-> uid, $ this-> pwd, $ this-> dbname ); // execute the SQL statement $ reslut = $ db-> query ($ SQL); // obtain the data if ($ type = 1) {$ attr = $ reslut-> fetch_all (); $ str = ""; foreach ($ attr as $ v) {$ str. = implode ("^", $ v); $ str. = "|";} return substr ($ str, 0, strlen ($ str)-1);} else {return $ reslut ;}}}