-
-
-
-
- // 設定資料庫
-
- define('DB_HOST, ' 127.0.0.1'); //伺服器位址
-
- define('DB_USER', 'root'); //使用者名稱
-
- define('DB_PASS', ''); //密碼
-
- define('DB_DATABASENAME', 'fenxiao'); //資料庫
-
-
-
-
-
-
-
- class Dbmy
-
- class Dbmy
- {
-
-
-
- /*
-
- *變數
-
- **/
-
- private $tablename=""; //表名
-
- private $fieldname="*";
-
- private $conn;
-
- private $where;
-
- private $sql; >
-
- function __construct($tablename)
-
- {
-
- //產生一個連線
-
- $this->conn = mysql_connect(DB_HOST,DB_USER, mysql_connect(DB_HOST,DB_USER, mysql_connect(DB_HOST,DB_USER, mysql_connect(DB_HOST,DB_USER, mysql_connect(DB_HOST,DB_USER, mysql_connect(DB_HOST,DB_USER, mysql_connect(DB_HOST,DB_USER, mysql_connect( ) or die("connect failed" . mysql_error());
-
- //選擇資料庫
-
- mysql_select_db(DB_DATABASENAME, $this->conn);
- >編碼格式
-
- mysql_query("SET NAMES utf8");
-
- //var_dump($conn);
-
- $this->tablename=$tablename;
-
-
-
- }
-
-
-
- //設定sql語句
-
- private function setsql($sql)
-
- {
-
- this>
- this> sql=$sql;
-
- }
-
-
-
- //設定條件語句
-
- public function where($where)
-
- {
- {
-
- $this->where=" where ".$where;
-
-
-
- return $this;
-
- }
-
-
-
- }
-
-
-
- }
-
-
-
- }
-
-
-
- }
-
-
-
- }
-
-
-
-
- //依指定欄位
-
- public function field($keyword)
-
- {
-
- $this->fieldname=$keyword;
-
- return $this;
-
- }
-
- //設定連線查詢表
-
- public function table($table1,$table2,$field,$bool)
-
- {
-
- $this->tablename="$table1 LEFT JOIN $table2 ON $table1.$field$bool$table2.$field";
-
- //print_r($this->tablename );
-
- return $this;
-
- }
-
-
-
- //設定多表查詢
-
- public function addtable($table1,addtable($table1,addtable($table1,addtable($table1,addtable($table1) $table2,$field,$bool)
-
- {
-
- $this->tablename.=" LEFT JOIN $table2 ON $table1.$field$bool$table2.$field";
-
- //print_r($this->tablename);
-
- return $this;
-
- }
-
-
-
- //設定連接查詢表
-
- ##SELECT * FROM 【wx_order LEFT JOIN wx_shopcar ON wx_shopcar.oid=wx_order.oid and wx_order.uid=wx_shopcar.uid LEFT JOIN wx_goods ON wx_good.g; 1 and wx_order.uid=3
-
- public function settable($sql)
-
- {
-
- $this->tablename=$sql;
-
- // print_r($this->tablename);
-
- return $this;
-
- }
-
-
-
- //查詢所有資料庫以數組形式輸出
-
-
- //查詢所有資料庫以數組形式輸出
-
- public function select()
-
- {
-
- /**
-
- * 查詢資料庫中所有的資料
-
- **/
-
- $arr=array();
-
-
- $arr=array();
-
- //執行sql語句
-
- $result = mysql_query("select ".$this->fieldname." from ".$this->tablename.$this->where, $this->conn);
-
-
-
- while ($row = mysql_fetch_assoc($result)) {
-
-
-
- array_push($arr, $row);
-
- array_push($arr, $row);
-
- }
- }
-
-
-
- return $arr;
-
- }
-
-
-
- //搜尋指定欄位資料
- publicunction find( )
-
- {
-
- //執行sql語句
-
- $result = mysql_query("select ".$this->fieldname." from ".$this->tablename. $this->where, $this->conn);
-
- $result = mysql_fetch_assoc($result);
-
- return $result;
-
- }
-
-
-
- //增加資料到資料庫
-
- public function add($data)
-
- {
-
- $keysql='';
-
- $valuesql='';
-
- foreach ($data as $key => $value) {
-
- $keysql.=",`$key`";
-
- $valuesql.=",'$value'";
-
- }
-
- $keysql=substr($keysql, 1);
-
- $valuesql=substr($valuesql, 1);
-
- $result=mysql_query("insert into `".$this->tablename."` ($keysql) VALUES($valuesql)");
-
- $id=mysql_insert_id ();
-
- //print_r("insert into `".$this->tablename."` ($keysql) VALUES($valuesql)");
-
- return $id;
-
- }
- //修改資料庫的內容 public function save($data) { $keysql=''; $valuesql=''; foreach ($data as $key => $value) { $keysql.=",` $key`='$value'"; } $keysql=substr($keysql, 1); //print_r($keysql); //echo "
"; $result=mysql_query("UPDATE `".$this->tablename."` SET ".$keysql.$this->where); //print_r("UPDATE `".$this->tablename."` SET ".$keysql.$this->where); return $result; }
-
-
-
- ##刪除資料
-
- public function delete()
-
- {
-
- $result=mysql_query("DELETE FROM🎜>
- $result=mysql_query("DELETE FROM ->tablename $this->where");
-
- //print_r("DELETE FROM $this->tablename $this->where");
-
- return $result;
-
- }
-
-
-
- }
-
-
-
- /**
-
- * mysql_fetch_row: 傳回單列的各欄位 [0]=>"111"
-
- * mysql_fetch_field: 取得欄位資訊。 [0]=> ['name']=> object
-
- * mysql_fetch_array 傳回陣列資料。 [0]=>"asasds" ['name']=>
-
- */
-
?>
複製程式碼
|