比这篇新的文章:
Codee#856
比这篇旧的文章: How to make a Django ForeignKey optional
作者: crazybaby, 点击187次, 评论(0), 收藏者(0), , 打分:
所有评论,共0条:( 我也来说两句)
比这篇旧的文章: How to make a Django ForeignKey optional
Codee#855
语言: PHP, 标签: 无 2009/05/07发布 10个月前更新作者: crazybaby, 点击187次, 评论(0), 收藏者(0), , 打分:
PHP语言: Codee#855
001 <?php
002
003 class mysql//定义类
004 {
005
006 private $host;
007 private $name;
008 private $pass;
009 private $table;
010 private $ut;
011
012
013 function __construct($host,$name,$pass,$table,$ut)//构造函数
014 {
015 $this->host=$host;
016 $this->name=$name;
017 $this->pass=$pass;
018 $this->table=$table;
019 $this->ut=$ut;
020 $this->connect();
021
022 }
023
024 function connect()//链接数据库函数
025 {
026 $link=mysql_connect($this->host,$this->name,$this->pass) or die ($this->error());
027 mysql_select_db($this->table,$link) or die("没该数据库:".$this->table);//选择数据库
028 mysql_query("SET NAMES '$this->ut'");//选择编码
029 }
030
031 function query($sql, $type = '')
032 {
033 if(!($query = mysql_query($sql)))
034 {
035 $this->show('Say:', $sql);
036 }
037
038 return $query;
039 }
040
041 //基本函数
042 function show($message = '', $sql = '')
043 {
044 if(!$sql) echo $message;
045 else echo $message.'<br>'.$sql;
046 }
047
048 function affected_rows()
049 {
050 return mysql_affected_rows();
051 }
052
053 function result($query, $row)
054 {
055 return mysql_result($query, $row);
056 }
057
058 function num_rows($query)
059 {
060 return @mysql_num_rows($query);
061 }
062
063 function num_fields($query)
064 {
065 return mysql_num_fields($query);
066 }
067
068 function free_result($query)
069 {
070 return mysql_free_result($query);
071 }
072
073 function insert_id()
074 {
075 return mysql_insert_id();
076 }
077
078 function fetch_row($query)
079 {
080 return mysql_fetch_row($query);
081 }
082
083 function version()
084 {
085 return mysql_get_server_info();
086 }
087
088 function close()
089 {
090 return mysql_close();
091 }
092
093
094 //======功能性函数========
095
096 function fn_insert($table,$name,$value)//插入数据
097 {
098
099 $this->query("insert into $table ($name) value ($value)");
100
101 }
102
103
104 }
105
106
107 $db = new mysql('localhost','root','0225','books',"GBK");
108
109 //$db->fn_insert('test','id,title,dates',"'','我插入的信息',now()");
110
111
112
113 ?>
002
003 class mysql//定义类
004 {
005
006 private $host;
007 private $name;
008 private $pass;
009 private $table;
010 private $ut;
011
012
013 function __construct($host,$name,$pass,$table,$ut)//构造函数
014 {
015 $this->host=$host;
016 $this->name=$name;
017 $this->pass=$pass;
018 $this->table=$table;
019 $this->ut=$ut;
020 $this->connect();
021
022 }
023
024 function connect()//链接数据库函数
025 {
026 $link=mysql_connect($this->host,$this->name,$this->pass) or die ($this->error());
027 mysql_select_db($this->table,$link) or die("没该数据库:".$this->table);//选择数据库
028 mysql_query("SET NAMES '$this->ut'");//选择编码
029 }
030
031 function query($sql, $type = '')
032 {
033 if(!($query = mysql_query($sql)))
034 {
035 $this->show('Say:', $sql);
036 }
037
038 return $query;
039 }
040
041 //基本函数
042 function show($message = '', $sql = '')
043 {
044 if(!$sql) echo $message;
045 else echo $message.'<br>'.$sql;
046 }
047
048 function affected_rows()
049 {
050 return mysql_affected_rows();
051 }
052
053 function result($query, $row)
054 {
055 return mysql_result($query, $row);
056 }
057
058 function num_rows($query)
059 {
060 return @mysql_num_rows($query);
061 }
062
063 function num_fields($query)
064 {
065 return mysql_num_fields($query);
066 }
067
068 function free_result($query)
069 {
070 return mysql_free_result($query);
071 }
072
073 function insert_id()
074 {
075 return mysql_insert_id();
076 }
077
078 function fetch_row($query)
079 {
080 return mysql_fetch_row($query);
081 }
082
083 function version()
084 {
085 return mysql_get_server_info();
086 }
087
088 function close()
089 {
090 return mysql_close();
091 }
092
093
094 //======功能性函数========
095
096 function fn_insert($table,$name,$value)//插入数据
097 {
098
099 $this->query("insert into $table ($name) value ($value)");
100
101 }
102
103
104 }
105
106
107 $db = new mysql('localhost','root','0225','books',"GBK");
108
109 //$db->fn_insert('test','id,title,dates',"'','我插入的信息',now()");
110
111
112
113 ?>
所有评论,共0条:( 我也来说两句)
代码
