📄 00000007.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: yanglc (天天改昵称比较的烦), 信区: Linux <BR>标 题: MySQL & PHP--7 <BR>发信站: BBS 水木清华站 (Tue Jun 20 22:23:28 2000) <BR> <BR>util.php3 <BR> <BR>这里是我们编写的 MySQL 用于PHP的库, 它能帮助你对数据库进行操作. <BR> <BR><? <BR>/* <BR> * Utility routines for MySQL. <BR> */ <BR> <BR>class MySQL_class { <BR> var $db, $id, $result, $rows, $data, $a_rows; <BR> var $user, $pass, $host; <BR> <BR> /* Make sure you change the USERNAME and PASSWORD to your name and <BR> * password for the DB <BR> */ <BR> <BR> function Setup ($user, $pass) { <BR> $this->user = $user; <BR> $this->pass = $pass; <BR> } <BR> <BR> function Create ($db) { <BR> if (!$this->user) { <BR> $this->user = "USERNAME"; /* 在这里作修改 */ <BR> } <BR> if (!$this->pass) { <BR> $this->pass = "PASSWORD"; /* 在这里作修改 */ <BR> } <BR> $this->db = $db; <BR> $this->id = @mysql_pconnect($this->host, $this->user, $this->pass) or <BR> MySQL_ErrorMsg("Unable to connect to MySQL server: $this->host : '$SERVER_NAME'"); <BR> $this->selectdb($db); <BR> } <BR> <BR> function SelectDB ($db) { <BR> @mysql_select_db($db, $this->id) or <BR> MySQL_ErrorMsg ("Unable to select database: $db"); <BR> } <BR> <BR> # Use this function is the query will return multiple rows. Use the Fetch <BR> # routine to loop through those rows. <BR> function Query ($query) { <BR> $this->result = @mysql_query($query, $this->id) or <BR> MySQL_ErrorMsg ("Unable to perform query: $query"); <BR> $this->rows = @mysql_num_rows($this->result); <BR> $this->a_rows = @mysql_affected_rows($this->result); <BR> } <BR> <BR> # Use this function if the query will only return a <BR> # single data element. <BR> function QueryItem ($query) { <BR> $this->result = @mysql_query($query, $this->id) or <BR> MySQL_ErrorMsg ("Unable to perform query: $query"); <BR> $this->rows = @mysql_num_rows($this->result); <BR> $this->a_rows = @mysql_affected_rows($this->result); <BR> $this->data = @mysql_fetch_array($this->result) or <BR> MySQL_ErrorMsg ("Unable to fetch data from query: $query"); <BR> return($this->data[0]); <BR> } <BR> <BR> # This function is useful if the query will only return a <BR> # single row. <BR> function QueryRow ($query) { <BR> $this->result = @mysql_query($query, $this->id) or <BR> MySQL_ErrorMsg ("Unable to perform query: $query"); <BR> $this->rows = @mysql_num_rows($this->result); <BR> $this->a_rows = @mysql_affected_rows($this->result); <BR> $this->data = @mysql_fetch_array($this->result) or <BR> MySQL_ErrorMsg ("Unable to fetch data from query: $query"); <BR> return($this->data); <BR> } <BR> <BR> function Fetch ($row) { <BR> @mysql_data_seek($this->result, $row) or <BR> MySQL_ErrorMsg ("Unable to seek data row: $row"); <BR> $this->data = @mysql_fetch_array($this->result) or <BR> MySQL_ErrorMsg ("Unable to fetch row: $row"); <BR> } <BR> <BR> function Insert ($query) { <BR> $this->result = @mysql_query($query, $this->id) or <BR> MySQL_ErrorMsg ("Unable to perform insert: $query"); <BR> $this->a_rows = @mysql_affected_rows($this->result); <BR> } <BR> <BR> function Update ($query) { <BR> $this->result = @mysql_query($query, $this->id) or <BR> MySQL_ErrorMsg ("Unable to perform update: $query"); <BR> $this->a_rows = @mysql_affected_rows($this->result); <BR> } <BR> <BR> function Delete ($query) { <BR> $this->result = @mysql_query($query, $this->id) or <BR> MySQL_ErrorMsg ("Unable to perform Delete: $query"); <BR> $this->a_rows = @mysql_affected_rows($this->result); <BR> } <BR>} <BR> <BR>/* ******************************************************************** <BR> * MySQL_ErrorMsg <BR> * <BR> * Print out an MySQL error message <BR> * <BR> */ <BR> <BR>function MySQL_ErrorMsg ($msg) { <BR> # Close out a bunch of HTML constructs which might prevent <BR> # the HTML page from displaying the error text. <BR> echo("</ul></dl></ol>\n"); <BR> echo("</table></script>\n"); <BR> <BR> # Display the error message <BR> $text = "<font color=\"#ff0000\" size=+2><p>Error: $msg :"; <BR> $text .= mysql_error(); <BR> $text .= "</font>\n"; <BR> die($text); <BR>} <BR>?> <BR>-- <BR> 欢迎光临【静园草坪】BBS 站 <BR> telnet://bbs.geo.pku.edu.cn <BR> telnet://162.105.20.254 <BR> 个人主页 <BR> <A HREF="http://www2.cs.uestc.edu.cn/~yanglc">http://www2.cs.uestc.edu.cn/~yanglc</A> <BR> <BR> <BR>※ 来源:·BBS 水木清华站 smth.org·[FROM: 166.111.214.121] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -