<无详细内容>
- /**
- * @package Database Class
- * @author Injection (mail:injection.mail@gmail.com)
- * @version 1.0
- */
- @ini_set (' Display_errors ', 0);
- Class database{
- Private $mDb _host, $mAb _user, $mAb _pwd, $mConn _no;
- function DataBase ($Conn _obj) {
- $this->connectdb ($Conn _obj);
- }
- function Connectdb ($Conn _obj) {
- $this->mdb_host = $Conn _obj->host;
- $this->mad_name = $Conn _obj->user;
- $this->mad_pwd = $Conn _obj->pwd;
- $this->mconn_no = mysql_connect ($this->mdb_host, $this->mad_name, $this->mad_pwd);
- }
- function Selectdb ($Conn _obj) {
- $this->mdb_name = $Conn _obj->dbname;
- mysql_select_db ($this->mdb_name);
- }
- }
- /**
- * @package Making Sqls class Exetends Database class
- * @author Injection (mail:injection.mail@gmail.com)
- * @version 1.0
- */
- Class Makesql extends database{
- Private $MSQL;
- function Makesql ($type, $arr _colum_list, $arr _sql_choice) {
- $this->makesqltype ($arr _colum_list, $arr _sql_choice);
- }
- #switch Make List
- function Makesqltype ($type, $arr _colum_list, $arr _sql_choice) {
- Switch ($type) {
- Case ' Insert ':
- return $this->makeinsert ($arr _colum_list, $arr _sql_choice);
- Case ' SELECT ':
- return $this->makeselect ($arr _colum_list, $arr _sql_choice);
- Case ' Update ':
- return $this->makeupdate ($arr _colum_list, $arr _sql_choice);
- Case ' Delete ':
- return $this->makedelete ($arr _colum_list, $arr _sql_choice);
- }
- }
- #make Insert
- function Makeinsert ($arr _colum_list, $arr _sql_choice) {
- $colum _key = Array_keys ($arr _colum_list);
- $colum _value = array_values ($arr _colum_list);
- $this->msql = "INSERT into". $arr _sql_choice["Tbl_name"]. " (". Join (', ', $colum _key).") VALUES (' ". Join (" ', ' ", $colum _value)." ') ";
- return $this->msql;
- }
- #making Select
- function Makeselect ($arr _colum_list = ' * ', $arr _sql_choice) {
- $colum _value = Array_keys ($arr _colum_list);
- foreach ($arr _sql_choice as $sql _key = $sql _value) {
- if (strcmp ($sql _key, ' tbl_name ') = = 0) {
- if (strcmp ($arr _colum_list, ' * ')!== 0)
- $this->msql = "select". Join (', ', $colum _value). " From ". $sql _value;
- Else
- $this->msql = "SELECT * from". $sql _value;
- }
- Else
- if (strcmp ($sql _value, ')!== 0)
- if (strcmp ($sql _key, ' WHERE ') = = = 0 && strcmp ($sql _value, ' colum ') = = = 0) {
- foreach ($arr _colum_list as $colum _key = $colum _value)
- $this->msql. = "$colum _key = ' $colum _value ' and";
- $this->msql = RTrim ($this->msql, "and");
- }
- Else
- $this->msql. = "$sql _key". $sql _value;
- }
- return $this->msql;
- }
- #making Update
- function Makeupdate ($arr _colum_list, $arr _sql_choice) {
- $this->msql = "UPDATE". $arr _sql_choice[' tbl_name ']. " SET ";
- foreach ($arr _colum_list as $colum _key = $colum _value)
- $this->msql. = "$colum _key = ' $colum _value ',";
- $this->msql = RTrim ($this->msql, ', ');
- foreach ($arr _sql_choice as $sql _key = $sql _value) {
- if (strcmp ($sql _value, ')!== 0 && strcmp ($sql _key, ' tbl_name ')!==0 && strcmp ($sql _key, ' ORDER by ' )!== 0)
- $this->msql. = "$sql _key". $sql _value;
- }
- return $this->msql;
- }
- #making Delete
- function Makedelete ($arr _colum_list, $arr _sql_choice) {
- $this->msql = "DELETE from". $arr _sql_choice[' tbl_name '];
- foreach ($arr _sql_choice as $sql _key = $sql _value) {
- if (strcmp ($sql _key, ' tbl_name ')!== 0 && strcmp ($sql _value, ')!== 0) {
- $this->msql. = "$sql _key". $sql _value;
- }
- }
- return $this->msql;
- }
- }
Copy Code |