PHP's Sqlhelp

Source: Internet
Author: User
 Pre = $pre;                $this->connect ($host, $user, $pwd, $db);        Mysql:: $self = $this; }/** * @param string $host * @param string $host * @param string $pwd * @p Aram 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 could not                be established. '); if (! mysql_select_db ($db, $this->link)) die (' Database could not be selected. '); /** * Execute SQL * @param string $sql * @return Mysql */Public function Quer                Y ($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 ' = = $sql);        return $this; /** * Gets a single query value * @param string $sql * @return Mixed */Public function get                One ($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; }/** * Gets a record * @param string $sql * @return Array */Public function Getr                ow ($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 func                tion 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 insert ID * @return int */Public Function Insertid ($seq =0) {        Return mysql_insert_id ($this->link); }/** * Gets the number of rows affected * @return int */Public Function Rownummber () {retur        N $this->rows; }/** * Check whether the query was successful * @return BOOL */Public Function check () {return $ This->q = = = False?        False:true;                /** * Get Connected * @return Resource */Public Function GetLink () {        return $this->link; }/** * Get query statement for this connection * @return string        */Public Function GetSQL () {return $this->sql; }/** * Gets the class name * @return String */Public Function __tostring () {retur        n __class__; /** * Get Execution time * @return float */Public Function Gettimeinfo () {RET        Urn $this->alltime; }/** * Get execution times * @return Int */Public Function gettimes () {return $        this->times; /** * Get result row number * @return Int */Public Function getresultrows () {$ro                WS = 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 last execution statement error * @desc GetLastError * @access public * @return S Tring * @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 2009-9-25 pm 02:06:41 * @versi On $Revision: 685 $ */Public Function Escape ($sql) {return mysql_real_escape_string ($sq        L, $this->link); }}?> initialization:
 GetOne ($sql), $line = $db->getrow ($sql), $all = $db->getall ($sql);//other file global $db; $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.