PHP tool-type MySQL add, delete, modify, and query tool-type mysql

Source: Internet
Author: User

PHP tool-type MySQL add, delete, modify, and query tool-type mysql

? Php header ("content-type: text/html; charset = UTF-8 "); class DBUtils {/*** General update method insert update delete operation * @ param SQL * @ return bool true false */public function update ($ SQL) {$ link = $ this-> getConn (); mysql_query ($ SQL); // if an error is displayed, if (DEBUG) {echo mysql_error ();} $ rs = mysql_affected_rows ($ link); $ rs = $ rs> 0; mysql_close ($ link); return $ rs ;} /*** select Operation for common Query Method * @ param SQL * @ return array */public Function queryRows ($ SQL) {// create a connection, code, database $ link = $ this-> getConn (); // send SQL $ rs = mysql_query ($ SQL ); // if an error is displayed, if (DEBUG) {echo mysql_error () ;}$ rows = array (); while ($ row = mysql_fetch_array ($ rs )) {$ rows [] = $ row; // pdemo7.php} // mysql_free_result ($ rs); mysql_close ($ link); return $ rows ;} /*** common query method: select Operation query result: a row of Data * @ param SQL * @ return array returns false if the query fails. */public function queryRow ($ SQL) {$ rs = $ This-> queryRows ($ SQL); if (! Empty ($ rs [0]) {return $ rs [0];} return false ;} /*** common query method: select Operation query result: a data * @ param SQL * @ return array returns false if the query fails. * example: select count (*) from user; */public function queryObj ($ SQL) {$ rs = $ this-> queryRows ($ SQL); // var_dump ($ rs); if (! Empty ($ rs [0] [0]) {return $ rs [0] [0];} return false;} private function getConn () {$ link = mysql_connect ('2017. 0.0.1 ', 'root', ''); mysql_query (" set names utf8 "); mysql_select_db (" news "); return $ link ;}}

  

Related Article

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.