Link database encapsulation class, link database Encapsulation

Source: Internet
Author: User

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

 

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.