当前位置:学学看123知识中心电脑教学数据库教程MySQL数据库类的定义» 正文

MySQL数据库类的定义

[06-11 18:15:11]   来源:http://www.xxk123.com  数据库教程   阅读:8824

导读: $totlerows=$db->getcount("select * from mytable"); echo "共有 $totlerows 条信息。"; */ function getcount($sql){ return @mysql_num_rows($this->query($sql)); }/* 以下函数用于更新数据库,例如用户更改密码: $db->update("update user set password='$new_password' where userid='$userid' "); */ function update($sql)

MySQL数据库类的定义,标签:sql数据库教程,access数据库教程,http://www.xxk123.com
$totlerows=$db->getcount("select * from mytable");
echo "共有 $totlerows 条信息。";
*/
function getcount($sql){
return @mysql_num_rows($this->query($sql));
}

/*
以下函数用于更新数据库,例如用户更改密码:
$db->update("update user set password='$new_password' where userid='$userid' ");
*/
function update($sql){
return $this->query($sql);
}

/*
以下函数用于向数据库插入一行,例如添加一个用户:
$db->insert("insert into user (userid,username,password) values (null,'$username','$password')");
*/
function insert($sql){
return $this->query($sql);
}

function getid(){ //这个函数用于取得刚插入行的id
return mysql_insert_id();
}
}

/*
主要函数就是这些,如果你自己有另外的需要,也可以自己添加上去。
因为凡使用该类的都必须连接数据库,下面就连接并选择好数据库吧:
*/
$db=new dbClass("$db_username","$db_password","$db_database","$db_hostname");
$db->connect();
$db->select();

?>

OK,数据库的类已经写好了,它不但可以用在目前这个项目中,其他项目的同样适用!只要把“dbclass.php”复制过去就行了。要用本文件的时候只要用语句“include_once("dbclass.php")”就行,具体语法在编写数据库类时已有举例,不再赘述。

写好数据库的类后,数据库的操作就方便多了,项目的制作已跨出了重要的第一步。

  上一篇      目录      下一篇 来源:unknown   ◆ 本站相关教程 MySQL的数据类型和建库策略MySQL怎样优化WHERE子句用gcc批量建mysql库表不同平台上mysql的对比使一个新的MySQL安装更安全将OICQ数据转成MYSQL数据MySQL数据库类的定义

上一页  [1] [2] [3] [4] [5] 


Tag:数据库教程sql数据库教程,access数据库教程电脑教学 - 数据库教程

Copyright 学学看123 All Right Reserved.

1 2 3 4 5 6 7 8 9 10