搜尋
首頁php教程php手册php开发_链接mysql数据库的一个类

php开发_链接mysql数据库的一个类

Jun 13, 2016 am 10:48 AM
classcomysqlphp開發效果資料庫類別結構運行連結專案


 项目结构:

运行效果;




conn.php
 
 1  2 class ConnectionMySQL{
 3     //主机
 4     private $host="localhost";
 5     //数据库的username
 6     private $name="root";
 7     //数据库的password
 8     private $pass="";
 9     //数据库名称
10     private $table="phptest";
11     //编码形式
12     private $ut="utf-8";
13
14
15     //构造函数
16     function __construct(){
17         $this->ut=$ut;
18         $this->connect();
19
20     }
21
22     //数据库的链接
23     function connect(){
24         $link=mysql_connect($this->host,$this->name,$this->pass) or die ($this->error());
25         mysql_select_db($this->table,$link) or die("没该数据库:".$this->table);
26         mysql_query("SET NAMES '$this->ut'");
27     }
28
29     function query($sql, $type = '') {
30         if(!($query = mysql_query($sql))) $this->show('Say:', $sql);
31         return $query;
32     }
33
34     function show($message = '', $sql = '') {
35         if(!$sql) echo $message;
36         else echo $message.'
'.$sql;
37     }
38
39     function affected_rows() {
40         return mysql_affected_rows();
41     }
42
43     function result($query, $row) {
44         return mysql_result($query, $row);
45     }
46
47     function num_rows($query) {
48         return @mysql_num_rows($query);
49     }
50
51     function num_fields($query) {
52         return mysql_num_fields($query);
53     }
54
55     function free_result($query) {
56         return mysql_free_result($query);
57     }
58
59     function insert_id() {
60         return mysql_insert_id();
61     }
62
63     function fetch_row($query) {
64         return mysql_fetch_row($query);
65     }
66
67     function version() {
68         return mysql_get_server_info();
69     }
70
71     function close() {
72         return mysql_close();
73     }
74
75     //向$table表中插入值 www.2cto.com
76     function fn_insert($table,$name,$value){
77         $this->query("insert into $table ($name) value ($value)");
78     }
79     //根据$id值删除表$table中的一条记录
80     function fn_delete($table,$id,$value){
81         $this->query("delete from $table where $id=$value");
82         echo "id为". $id." 的记录被成功删除!";
83     }
84 }
85
86 $db =  new ConnectionMySQL();
87
88 $db->fn_insert('test','id,name,sex',"'','hongtenzone','M'");
89 $db->fn_delete('test', 'id', 1);
90
91 ?>
 

 摘自 Hongten

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。