php面向对象文件名DB.class.php
<?phpheader("content-type:text/htmlcharset=utf-8")
class DB{
public $db_host//localhost
public $db_user//用户名
public $db_pwd//密码
public $db_name//数据库名
public $links//链接名称
//构造方法的参数和属性名字一致,但是含义不同
function __construct($db_host,$db_user,$db_pwd,$db_name){
$this -> db_host = db_host
$this -> db_user = db_user
$this -> db_pwd = db_pwd
$this -> db_name = db_name
//链接数据库代码
$this -> links = @mysql_connect($db_host,$db_user,$db_pwd)or die("数据库链接失败")
//echo $this -> links打印是资源
mysql_query("set names utf8")
mysql_select_db($db_name,$this->links)
}
function query($sql){//执行各种sql,inert update delete执行,如果执行select返回结果集
return mysql_query($sql)
}
function numRows($sql){//返回select的记录数
$result = $this -> query($sql)
$count = mysql_num_rows($result)
return $count
}
function getOne($sql){//得到一条记录的一维数组
$result = $this -> query($sql)
$arr = mysql_fetch_assoc($result)
return $arr
}
function getAll($sql){//得到多条记录的二维数组
$result = $this -> query($sql)
$rows = array()
while($rs = mysql_fetch_assoc($result)){
$rows[] = $rs
}
return $rows
}
function __destruct(){
$this -> db_host = db_host
$this -> db_user = db_user
$this -> db_pwd = db_pwd
$this -> db_name = db_name
}
}
$db = new DB("localhost","root","","car")
//$sql = "insert into category(categoryName)values('常熟seo')"
//$db -> query($sql)
//返回select的记录数
//$sql = "select * from category"
//$count = $db -> numRows($sql)
//echo $count
//得到一条记录的一维数组
//$sql = "select * from category where categoryId=1"
//$arr = $db -> getOne($sql)
//print_r($arr)
//得到多条记录的二维数组
$sql = "select * from category"
$rs = $db -> getAll($sql)
print_r($rs)
?>
创建一个数据库大类
第一步:Iis安装(这个想必大家都会吧)第二步:配置PHP
1.PHP解压到 c:/php4 (所有文件都在php4下
2.搜索*.dll 复制到 c:/windows/system32
3.在PHP里面找 php.ini-recomndnded
复制到c:/windows 下面更名为:php.ini
并修改配置php.ini
需配置的东西:
a.register_globals= on
b. 去掉前面的分号file uploads upload_tmp_dir =c:php4tmp
(上传文件的位置)
c.upload_nax_filesile=2M (这个限制上传文件的大小)
D.session
Session.save_path=c:php4tmp
改过后重新启动IIS
4.在PHP4下面建立一文件夹tmp (权限 ever*) tmp (所有权限)
第三步:配置PHPMYADMIN
1.新建网站 PHPMYADMIN (端口 8899)
2.建c:inetpubwwwrootphpmyadmin建web
3.把PHPMYADMIN复制到c:inetpubwwwrootphpmyadmin建web
4.配置 config.inc.php
a. $cft[‘pmaAbsloutevri’]=’http://’.$GLOBALS[“http_server_vars”][‘http_host’].’/’(也可以直接用IP代替)
b. $cfg[‘blowfisg_sevret’]=”随便“
c. $cfg[‘servers’][$I][‘auth_type’]=’cookie’
第四步:配置MYSQL
1.运行SETUP.EXE
2.C:MYSQLBIN
3.把mysql data 保存到 d:mysqldata
4.新建网站 phpmyadmin (端口:8899)
建c:intetpupwwwrootphpmyadmin建web
把PHPADMIN直接复制到这里
配置 config.inc.php
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)