SqlHelp of PHP

Source: Internet
Author: User
SqlHelp of PHP
 Pre = $ pre; $ this-> connect ($ host, $ user, $ pwd, $ db); Mysql: $ self = $ this ;} /*** @ param string $ host * @ param string $ pwd * @ param string $ db * @ param string $ pre * @ return DB */public static function init ($ host = '', $ user = '', $ pwd ='', $ db = '', $ pre ='') {if (! (Mysql: $ self instanceof DB) {Mysql: $ self = new Mysql ($ host, $ user, $ pwd, $ db, $ pre);} return Mysql:: $ self;}/*** create connection */private function connect ($ host, $ user, $ pwd, $ db, $ pre = '') {$ this-> pre = $ pre; if (! $ This-> link = mysql_connect ($ host, $ user, $ pwd) die ('connection to mysql server cocould not be established. '); if (! Mysql_select_db ($ db, $ this-> link) die ('database could not be selected. ');}/*** run SQL * @ param string $ SQL * @ return Mysql */public function query ($ SQL) {$ this-> times ++; $ this-> begintime = microtime (); mysql_query ('set names '. self: $ charset, $ this-> link); $ this-> SQL = $ SQL; $ this-> q = mysql_query ($ SQL, $ this-> link ); $ this-> alltime [] = array ('t' => microtime ()-$ this-> begintime,'s '=> $ sq L); return $ this;}/*** get a single query value * @ param string $ SQL * @ return mixed */public function getOne ($ SQL = '') {if (strlen (trim ($ SQL)> 0) {$ this-> query ($ SQL);} if ($ this-> check ()) {$ result = mysql_fetch_array ($ this-> q, MYSQL_NUM); mysql_free_result ($ this-> q); return $ result [0];} return false ;} /*** get a record * @ param string $ SQL * @ return array */public function getRow ($ SQL = '') {if (strlen (trim ($ SQL)> 0) {$ this-> query ($ SQL);} if ($ this-> check ()) {$ result = mysql_fetch_assoc ($ this-> q); mysql_free_result ($ this-> q); return $ result;} else {return array ();}} /*** get all queries * @ param string $ SQL * @ return array */public function getAll ($ SQL = '') {if (strlen (trim ($ SQL)> 0) {$ this-> query ($ SQL) ;}$ return = array (); if ($ this-> check () {while ($ temp = mysql_fetch_assoc ($ this-> q) $ return [] = $ Temp; $ this-> rows = mysql_num_rows ($ this-> q); mysql_free_result ($ this-> q); return $ return;} else {return array ();}} /*** get the insert ID * @ return int */public function InsertId ($ seq = 0) {return mysql_insert_id ($ this-> link );} /*** obtain the number of affected rows * @ return int */public function rowNummber () {return $ this-> rows ;} /*** check whether the query is successful * @ return bool */public function check () {return $ this-> q = false? False: true;}/*** get connection * @ return resource */public function getLink () {return $ this-> link ;} /*** obtain the query statement for this connection * @ return string */public function getSQL () {return $ this-> SQL ;} /*** obtain the CLASS name * @ return string */public function _ toString () {return _ CLASS __;} /*** get execution time * @ return float */public function getTimeInfo () {return $ this-> alltime ;} /*** get the execution count * @ return Int */public functio N getTimes () {return $ this-> times;}/*** get the result row * @ return Int */public function getResultRows () {$ rows = mysql_num_rows ($ this-> q); mysql_free_result ($ this-> q); return $ rows;}/*** $ Id: Mysql. php 685 2009-12-03 10: 49: 04Z HH. sun $ * get the error of the last statement executed * @ desc getLastError * @ access public * @ return string * @ version $ Revision: 685 $ */public function getLastError () {return mysql_error ($ this-> link ); }/*** $ Id: Mysql. php 685 2009-12-03 10: 49: 04Z HH. sun $ * mysql_real_escape_string call * @ desc escape * @ access public * @ param string $ SQL * @ return string ** @ since 02:06:41 * @ version $ Revision: 685 $ */public function escape ($ SQL) {return mysql_real_escape_string ($ SQL, $ this-> link) ;}}?> Initialization:
 GetOne ($ SQL); $ line = $ db-> getRow ($ SQL); $ all = $ db-> getAll ($ SQL); // global $ db for other files; $ SQL = ".................................... ............ "; $ one = $ db-> getOne ($ SQL); $ line = $ db-> getRow ($ SQL ); $ all = $ db-> getAll ($ SQL);?>

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.