PHP簡單封裝MysqlHelper類

2022-03-19 04:07:35 字數 3734 閱讀 6586

1:

<?php

2:
3:

/**

4:

* mysql資料幫助類

5:

*/

6:

class mysqlhelper

7:
11:

//建立連線物件

12:         $this->conn=@mysql_connect($this->host,$this->uid,$this->pwd);
13:

if(!$this->conn)

16:
17:

//選擇資料庫和設定編碼

18:         mysql_select_db($this->db,$this->conn);
19:         mysql_query('set names utf8');
20:     }
21:
22:

private $conn;

23:

private $host='localhost';

24:

private $uid='root';

25:

private $pwd='1234';

26:

private $db='test2';

27:
28:

/**

29:

* [execute_dql 執行查詢語句]

30:

* @param [string] $sql [查詢語句]

31:

*/

32:

public

function execute_dql($sql)

33:
37:
38:

/**

39:

* [execute_dml 執行增刪改語句]

40:

* @param [string] $sql [查詢語句]

41:

* @return [失敗返回-1,無影響返回0,成功返回受影響的行數]

42:

*/

43:

public

function execute_dml($sql)

44:     else
51:     }
52:
53:

/**

54:

* [show_table_data 顯示表資料]

55:

* @param [string] $tablename [表名]

56:

* @return [string] [html**]

57:

*/

58:

public

function show_table_data($tablename)

59:
67:
68:

/**

69:

* [show_table_info 顯示表結構]

70:

* @param [string] $tablename [表名]

71:

* @return [string] [html**]

72:

*/

73:

public

function show_table_info($tablename)

74:
82:
83:

/**

84:

* [show_table 拼接**]

85:

* @param [resource] $result [結果集]

86:

* @return [string] [html]

87:

*/

88:

public

function show_table($result)

89:
97:         $tabledata.="";
98:
99:

//顯示資料資訊:

100:

while ($row = mysql_fetch_object($result))

105:             $tabledata.="";
106:         }
107:         $tabledata.="";
108:
109:

echo $tabledata;

110:     }
111: }
112:
113: ?>

<?php

2: header("content-type:text/html; charset=utf8");
3:
4:

//自定義mysqlhelper的測試與使用

5:

//****************************************====

6:
7:

//引用自定義的mysqlhelper類

8:

require_once

"mysqlhelper.class.php";

9:
10:

//例項化mysqlhelper物件

11: $execute = new mysqlhelper();
12:
13:

// 增

14: $sql = "insert into userinfo(uname,uage,upwd) values('測試04',18,md5('1234'));";
15:

// 刪

16:

// $sql = "delete from userinfo where id=20";

17:

// 改

18:

// $sql = "update userinfo set uage=19 where id=21";

19:
20:

//對資料執行dml操作

21: $returnnum = $execute->execute_dml($sql);
22:

if ($returnnum ==-1) else

27:
28:
29:

//顯示表資訊:

30: $execute->show_table_info("userinfo");
31:
32:

//顯示表資料:

33: $execute->show_table_data("userinfo");
34:
35:
36: ?>

簡單實用的php連線mysql封裝類

created on 2011 9 26 filename db mysql.php author by tianqixin class db mysql 設定查詢字符集 mysql query set character set connection character set results c...

Linux Epoll簡單封裝

1 單獨起執行緒進行epoll時間的偵聽 2 接收到事件後的預處理 printerr file line handler on recv and send socket event err,null,0 m cache.set usedbuf t buf close event data.fd re...

C SQLite 簡單封裝

sqlitehelper類 1 using system 2using system.configuration 3using system.data 4using system.data.sqlite 56 namespace myblog.data 7 29 1 2 初始化 sqlitehelp...