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