导航:首页 > 文件管理 > mysqlphp连接数据库配置文件

mysqlphp连接数据库配置文件

发布时间:2025-03-13 11:33:07

1. php怎么连接mysql数据库

1、新建一个php_mysql.php的文件


2. php连接 mysql 数据库如何添加一个公共的配置文件

php面向对象文件名DB.class.php

<?php
header("content-type:text/html;charset=utf-8");
classDB{
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)ordie("数据库链接失败");
//echo$this->links;打印是资源
mysql_query("setnamesutf8");
mysql_select_db($db_name,$this->links);

}
functionquery($sql){//执行各种sql,inertupdatedelete执行,如果执行select返回结果集
returnmysql_query($sql);
}
functionnumRows($sql){//返回select的记录数
$result=$this->query($sql);
$count=mysql_num_rows($result);
return$count;
}
functiongetOne($sql){//得到一条记录的一维数组
$result=$this->query($sql);
$arr=mysql_fetch_assoc($result);
return$arr;
}
functiongetAll($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=newDB("localhost","root","","car");
//$sql="insertintocategory(categoryName)values('常熟seo')";
//$db->query($sql);

//返回select的记录数
//$sql="select*fromcategory";
//$count=$db->numRows($sql);
//echo$count;

//得到一条记录的一维数组
//$sql="select*fromcategorywherecategoryId=1";
//$arr=$db->getOne($sql);
//print_r($arr);

//得到多条记录的二维数组
$sql="select*fromcategory";
$rs=$db->getAll($sql);
print_r($rs);


?>

创建一个数据库大类

阅读全文

与mysqlphp连接数据库配置文件相关的资料

热点内容
ai文件颜色为什么变鲜艳 浏览:346
cad的文件存储在哪 浏览:406
大华dvr超级密码计算器破解 浏览:511
魅族网络格式怎么看 浏览:952
smt程序文件 浏览:707
小红伞专业卸载工具 浏览:527
多少钱的数据线比较好 浏览:792
appears滨崎步 浏览:526
appstrore审核 浏览:251
java池化实例 浏览:788
数据库课程设计模板 浏览:718
放置在桌面的文件 浏览:475
java包访问权限 浏览:409
word标准行距是多少 浏览:76
在word里面打钩 浏览:661
f420光猫怎么解除数据 浏览:492
读取txt文件某一行 浏览:200
javaswt设置图标 浏览:397
铣一个圆槽怎么编程 浏览:171
win7文件修改图标 浏览:463

友情链接