开发者网络 动网主机 支持论坛 邮局 帮助
当前位置:网络学院PHP技术数据库操作 → MySQL用于PHP的库, 对数据库进行操作
MySQL用于PHP的库, 对数据库进行操作
日期:2000年11月24日 作者: 人气:     [ ]
<?
/*
* Utility routines for MySQL.
*/

class MySQL_class {
var $db, $id, $result, $rows, $data, $a_rows;
var $user, $pass, $host;

/* Make sure you change the USERNAME and PASSWORD to your name and
* password for the DB
*/

function Setup ($user, $pass) {
$this->user = $user;
$this->pass = $pass;
}

function Create ($db) {
if (!$this->user) {
$this->user = "USERNAME"; /* 在这里作修改 */
}
if (!$this->pass) {
$this->pass = "PASSWORD"; /* 在这里作修改 */
}
$this->db = $db;
$this->id = @mysql_pconnect($this->host, $this->user, $this->pass) or
MySQL_ErrorMsg("Unable to connect to MySQL server: $this->host : '$SERVER_NAME'");
$this->selectdb($db);
}

function SelectDB ($db) {
@mysql_select_db($db, $this->id) or
MySQL_ErrorMsg ("Unable to select database: $db");
}

# Use this function is the query will return multiple rows. Use the Fetch
# routine to loop through those rows.
function Query ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->result);
}

# Use this function if the query will only return a
# single data element.
function QueryItem ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->result);
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch data from query: $query");
return($this->data[0]);
}

# This function is useful if the query will only return a
# single row.
function QueryRow ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->result);
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch data from query: $query");
return($this->data);
}

function Fetch ($row) {
@mysql_data_seek($this->result, $row) or
MySQL_ErrorMsg ("Unable to seek data row: $row");
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch row: $row");
}

function Insert ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform insert: $query");
$this->a_rows = @mysql_affected_rows($this->result);
}

function Update ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform update: $query");
$this->a_rows = @mysql_affected_rows($this->result);
}

function Delete ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform Delete: $query");
$this->a_rows = @mysql_affected_rows($this->result);
}
}

/* ********************************************************************
* MySQL_ErrorMsg
*
* Print out an MySQL error message
*
*/

function MySQL_ErrorMsg ($msg) {
# Close out a bunch of HTML constructs which might prevent
# the HTML page from displaying the error text.
echo("</ul></dl></ol>n");
echo("</table></script>n");

# Display the error message
$text = "<font color="#ff0000" size=+2><p>Error: $msg :";
$text .= mysql_error();
$text .= "</font>n";
die($text);
}
?>

原作者:不详
来源:中国PHP自由联盟

(出处:)

相关文章:
 
·MySQL,下一个被收购的对象?
·使用MySql ODBC进行MYsql和MS sql7的数据转换
·谈谈数据从sql server数据库导入mysql数据库的体验
·用PHP连mysql和oracle数据库性能比较
·购建ASP、CGI、PHP+MySQL运行环境——服务器运行环境配置全攻略(二)
·购建ASP、CGI、PHP+MySQL运行环境——服务器运行环境配置全攻略(一)
·接触 solaris : 安装 apache + php + mysql
·用php与mysql的电子贺卡程序
·在Linux下安装PHP,APACHE,MYSQL,PERL的方法
·如何在Jsp中使用JDBC来联结MySql
相关软件:
 
·新版Mysql管理大师
·PHP+MYSQL贺卡程序
·一个比较完善的PHP/MySQL电子商务方案
·PHP MySQL 数据库管理完整登录版
·PHP与MySQL交互使用详解
说明:本站部分内容收集于网络,如有侵犯您的权益请来信告知,我们会第一时间进行处理,谢谢
 → 特别推荐
 → 热点TOP10

关于本站 | 诚聘英才 | 业务合作 | 联系我们 | 广告合作 | 收藏本站

海口动网先锋网络科技有限公司版权所有
Copyright ? 2000 - 2003 AspSky.Net
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077