1<?PHP2 3 /**4 * Function Name: SqlTool.class.php5 * Function function: PHP to delete the database and change the operation class6 * Function Zhang Zhengui7 * Creation time: 2015-01-058 * Modified time:9 */Ten Header("Content-type:text/html;charset=utf-8"); One classsqltool{ A Private $conn; - Private $host= ' localhost '; - Private $root= ' Root '; the Private $password= ' '; - Private $dbname=test; - - function__construct () { + #code ... - $this->conn =mysql_connect($this->host,$this->root,$this->password) or die(' Failed to connect to database '.Mysql_error()); + mysql_select_db($this-dbname); AMysql_set_charset (' UTF8 '); at } - - /***************************DQL Operation ***********************************/ - Public functionEXECUTE_DQL ($sql){ - $res=mysql_query($sql,$this->conn) or die(Mysql_error()); - return $res; in } - to /****************************dml Operation ***********************************/ + Public functionEXECUTE_DML ($sql){ - $res=mysql_query($sql,$this->conn) or die(Mysql_error()); the if(!$res) { * #code ... $ return0;Panax Notoginseng}ElseIf(mysql_affected_rows($this->conn) > 0) { - #code ... the return1; +}Else{ A #code ... the return2; + } - } $ } $ - /******************* - $sql = "INSERT INTO User1 (id,name) VALUES (' 7 ', ' Lu Xun ')"; the //Create Objects - $sqlTool = new SqlTool;Wuyi $result = $sqlTool-Execute_dml ($sql); the if ($result = = 0) { - # code ... Wu echo "Failure"; - }elseif ($result = = 1) { About # code ... $ echo "Success"; - }elseif ($result = = 2) { - # code ... - echo "does not affect the number of rows"; A } + *******************/ the?>
PHP database additions and deletions to change the Operation class