php连接数据库配置文件 php连接指定数据库

PHP数据库连接,单独配置怎么弄的

重新看了一下··大概明白楼主意思了。

成都创新互联公司服务项目包括建始网站建设、建始网站制作、建始网页制作以及建始网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,建始网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到建始省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

你是不是下载了别人一个什么破J或是开源的系统?

现在不知道怎么连接数据?

在使用之前,您需要分别配置一下文件:

1.Connections/conn.php

2.api/conn.php

3.admin/connect.php

直接打开自己的网站,找到这三个PHP文件,然后将里面默认的数据库数据库名、数据库账号、数据库密码改为自己的数据库名、账号、密码就可以了

PHP网站怎么连接到数据库?

常规方式

常规方式就是按部就班的读取文件了。其余的话和上述方案一致。

// 读取配置文件内容

$handle = fopen("filepath", "r");            $content = fread($handle, filesize("filepath"));123

PHP解析XML

上述两种读取文件,其实都是为了PHP解析XML来做准备的。关于PHP解析XML的方式的博客有很多。方式也有很多,像simplexml,XMLReader,DOM啦等等。但是对于比较小型的xml配置文件,simplexml就足够了。

配置文件

?xml version="1.0" encoding="UTF-8" ?mysql

!-- 为防止出现意外,请按照此标准顺序书写.其实也无所谓了 --

hostlocalhost/host

userroot/user

password123456/password

dbtest/db

port3306/port/mysql12345678910

解析

?php/**

* 作为解析XML配置文件必备工具

*/class XMLUtil {

public static $dbconfigpath = "./db.config.xml";    public static function getDBConfiguration() {

$dbconfig = array ();        try {            // 读取配置文件内容

$handle = fopen(self::$dbconfigpath, "r");            $content = fread($handle, filesize(self::$dbconfigpath));            // 获取xml文档根节点,进而获取相关的数据库信息

$mysql = simplexml_load_string($content);            // 将获取到的xml节点信息赋值给关联数组,方便接下来的方法调用

$dbconfig['host'] = $mysql-host;            $dbconfig['user'] = $mysql-user;            $dbconfig['password'] = $mysql-password;            $dbconfig['db'] = $mysql-db;            $dbconfig['port'] = $mysql-port;            // 将配置信息以关联数组的形式返回

return $dbconfig;

} catch ( Exception $e ) {            throw new RuntimeException ( "mark读取数据库配置文件信息出错!/markbr /" );

}        return $dbconfig;

}

}1234567891011121314151617181920212223242526272829

数据库连接池

对于PHP程序而言,优化永无止境。而数据库连接池就在一定程度上起到了优化的作用。其使得对用户的每一个请求而言,无需每次都像数据库申请链接资源。而是通过已存在的数据库连接池中的链接来返回,从时间上,效率上,都是一个大大的提升。

于是,这里简单的模拟了一下数据库连接池的实现。核心在于维护一个“池”。

从池子中取,用毕,归还给池子。

?php/**x

*  PHP中的数据库 工具类设计

*  郭璞

*  2016年12月23日

*

**/class DbHelper {    private $dbconfig;    private $dbpool;    public $poolsize;    public function __construct($poolsize = 20) {        if (! file_exists ( "./utils.php" )) {            throw new RuntimeException ( "markutils.php文件丢失,无法进行配置文件的初始化操作!/markbr /" );

}else {

require './utils.php';

}        // 初始化 配置文件信息

$this-dbconfig = XMLUtil::getDBConfiguration ();        // 准备好数据库连接池“伪队列”

$this-poolsize = $poolsize;

$this-dbpool = array ();        for($index = 1; $index = $this-poolsize; $index ++) {

$conn = mysqli_connect ( $this-dbconfig ['host'], $this-dbconfig ['user'], $this-dbconfig ['password'], $this-dbconfig ['db'] ) or die ( "mark连接数据库失败!/markbr /" );

array_push ( $this-dbpool, $conn );

}

}    /**

* 从数据库连接池中获取一个数据库链接资源

*

* @throws ErrorException

* @return mixed

*/

public function getConn() {        if (count ( $this-dbpool ) = 0) {            throw new ErrorException ( "mark数据库连接池中已无链接资源,请稍后重试!/mark" );

} else {            return array_pop ( $this-dbpool );

}

}    /**

* 将用完的数据库链接资源放回到数据库连接池

*

* @param unknown $conn

* @throws ErrorException

*/

public function release($conn) {        if (count ( $this-dbpool ) = $this-poolsize) {            throw new ErrorException ( "mark数据库连接池已满/markbr /" );

} else {

array_push ( $this-dbpool, $conn );

}

}

}

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

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

?php

header("content-type:text/html;charset=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);

 

 

?

创建一个数据库大类

phpcms链接数据库的配置文件在哪

配置文件的位置在:caches\configs\database.php

找到文件后修改对应的数据库链接信息就可以了

用php怎么连接mysql数据库

首先搭建PHP开发运行环境,安装完成后再使用PHP连接mysql,代码操作步骤如下:

下载php_mysql.dll扩展,放到ext文件夹下,如果存在则跳过;

打开php.ini配置文件,去掉extension=php_mysql.dll项前面的分号,如果已取掉则跳过此步骤;

然后运行phpinfo();如果存在mysql项,则说明已经开启mysql扩展。

php连接mysql数据库操作:

运行结果:

分享文章:php连接数据库配置文件 php连接指定数据库
链接分享:https://www.cdcxhl.com/article6/hgpgog.html

成都网站建设公司_创新互联,为您提供外贸建站营销型网站建设定制开发网站营销Google

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设