欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CodeIgniter針對(duì)數(shù)據(jù)庫(kù)的連接、配置及使用方法

 更新時(shí)間:2016年03月03日 11:50:59   作者:彬彬寒靈  
這篇文章主要介紹了CodeIgniter針對(duì)數(shù)據(jù)庫(kù)的連接、配置及使用方法,結(jié)合實(shí)例形式分析了CodeIgniter針對(duì)數(shù)據(jù)庫(kù)的連接配置及常用操作技巧,需要的朋友可以參考下

本文實(shí)例講述了CodeIgniter針對(duì)數(shù)據(jù)庫(kù)的連接、配置及使用方法。分享給大家供大家參考,具體如下:

1. 數(shù)據(jù)庫(kù):

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文件中配置數(shù)據(jù)庫(kù)參數(shù):

$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目錄下測(cè)試文件db1.php內(nèi)容如下:

<?php
class Db1 extends Controller{
  function index(){
    $this->load->database();
    $query=$this->db->query("select name,pwd,email from users");
    foreach ($query->result() as $row) {//返回對(duì)象數(shù)組
      echo $row->name;
      echo $row->pwd;
      echo $row->email."<br>";
    }
    echo "Total Result==".$query->num_rows();
  }
}
?>

打開(kāi)瀏覽器敲入地址:

http://localhost:8888/index.php/MyController/db1

ok搞定!

我想大家肯定也遇到過(guò)連不上數(shù)據(jù)庫(kù)的問(wèn)題,我花費(fèi)了好些精力才解決這個(gè)問(wèn)題,現(xiàn)在告訴大家,希望對(duì)大家學(xué)習(xí)CodeIgniter這個(gè)優(yōu)秀的PHP框架有所幫助。

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《codeigniter入門(mén)教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php日期與時(shí)間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

相關(guān)文章

最新評(píng)論