您的位置:首页 > 编程语言 > PHP开发

将数据库常用的操作(连接数据库,获得所有数据,获得一条记录,获得一列记录,获得一条索引数组,获得一条关联数组)都给封装到db.class.php里面,谁需要谁继承这个类 注意:提交封装的类文件

2013-04-25 21:10 1051 查看
<?php

class dbname{

private $localhost;

private $root;

private $pass;

private $db_name;

public function __construct($localhost,$root,$pass,$db_name){

$this->localhost=$localhost;

$this->root=$root;

$this->pass=$pass;

$this->db_name=$db_name;

$this->query();

}

private function query(){

mysql_connect($this->localhost,$this->root,$this->pass);

mysql_select_db($this->db_name);

mysql_query("set names utf8");

}

public function getAll($sql){

$result = mysql_query($sql);

$rows=array();

while($row = mysql_fetch_assoc($result)){//返回的是多条记录

$rows[]=$row;

}

return $rows;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐