富贵资源网 Design By www.hznty.com

本文实例讲述了CodeIgniter针对数据库的连接、配置及使用方法。分享给大家供大家参考,具体如下:

1. 数据库:

create database test;
create table users(
id int not null,
name varchar(10),
pwd varchar(10),
email varchar(20)
)
insert into users values(1,'shunping','shunping','aa@163.com');
insert into users values(2,'shunping2','shunping2','bb@163.com');

2. 我用的是Postgreql
 
在\CodeIgniter\system\application\config\database.php文件中配置数据库参数:

$active_group = "default";
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "postgres";
$db['default']['password'] = "admin";
$db['default']['database'] = "test";
$db['default']['dbdriver'] = "postgre";
$db['default']['dbprefix'] = "";
$db['default']['active_r'] = TRUE;
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['port'] = "5432";

在\CodeIgniter\system\application\controllers目录下测试文件db1.php内容如下:

<"select name,pwd,email from users");
    foreach ($query->result() as $row) {//返回对象数组
      echo $row->name;
      echo $row->pwd;
      echo $row->email."<br>";
    }
    echo "Total Result==".$query->num_rows();
  }
}
"_blank" href="https://www.jb51.net/Special/32.htm">codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com