[Php]mysql Operation Flow

Source: Internet
Author: User

This is a relatively old MySQL connection method

1. Connect to the database

$this mysql_connect ($this$this$this->pswd);

2. Select Database

mysql_select_db ($this$this->con);

3. Operation

mysql_query ($sql$this->con);

4. Releasing Resources

Mysql_free_result ($this,res); Mysql_close ($this->con);

The object-oriented notation is as follows:

<?PHPclasssql{Private Static $con; Private Static $host= "localhost"; Private Static $user= "Root"; Private Static $pswd= "Root"; Private Static $db= "Test"; Private Static $res; SQL () {$this->con =mysql_connect($this->host,$this->user,$this-pswd); if(!$this-con) die("CON ERROR:".)Mysql_errno().Mysql_error()); $bool=mysql_select_db($this-&GT;DB,$this-con); if($bool)                 die("mysql_select_db ERROR:".)Mysql_errno().Mysql_error()); mysql_query("Set Names UTF8"); }        /*set host, DB, user, password*/        functionSet_attr ($host,$db,$user,$pswd){            $this->host =$host; $this->db =$db; $this->user =$user; $this-&GT;PSWD =$pswd; }        /*Add update delete and so on*/        functionExecute$sql){            $bool=mysql_query($sql,$this-con); if(!$bool)                 die("Mysql_select ERROR:".)Mysql_errno().Mysql_error()); Else{                if(mysql_affected_rows($this-con)) return0;//Now rows affect                Else                    return1;//Success            }        }        /*Select*/        functionExecute_query ($sql){            $res=mysql_query($sql,$this->con) or die("Mysql_query ERROR:".)Mysql_errno().Mysql_error()); returnRes; }        /*Release Resource*/        functionClose () {Mysql_free_result($this-res); Mysql_close($this-con); }    }?>

[Php]mysql Operation Flow

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.