Home  >  Article  >  Backend Development  >  CodeIgniter for database connection, configuration and usage, codeigniter database_PHP tutorial

CodeIgniter for database connection, configuration and usage, codeigniter database_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:57:52827browse

CodeIgniter's connection, configuration and use methods for databases, codeigniter database

This article describes the examples of CodeIgniter's connection, configuration and use methods for databases. Share it with everyone for your reference, the details are as follows:

1. Database:

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. I use Postgreql

Configure database parameters in the CodeIgnitersystemapplicationconfigdatabase.php file:

$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";

The content of the test file db1.php in the CodeIgnitersystemapplicationcontrollers directory is as follows:

<&#63;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) {//返回对象数组
      echo $row->name;
      echo $row->pwd;
      echo $row->email."<br>";
    }
    echo "Total Result==".$query->num_rows();
  }
}
&#63;>

Open your browser and type in the address:

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

ok done!

I think you must have encountered the problem of not being able to connect to the database. I spent a lot of energy to solve this problem. Now I tell you, I hope it will be helpful for you to learn CodeIgniter, an excellent PHP framework.

Readers who are interested in more PHP-related content can check out the special topics of this site: "Introduction to codeigniter tutorial", "CI (CodeIgniter) framework advanced tutorial", "php date and time usage summary", "php object-oriented program" Design introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

Articles you may be interested in:

  • Using Smarty3 basic configuration in CodeIgniter
  • CodeIgniter auxiliary third-party class library third_party usage analysis
  • CodeIgniter framework database Design flaws and solutions for transaction processing
  • Database configuration using codeigniter under Sina SAE cloud platform
  • Codeigniter integrated Tank Auth permission class library detailed explanation
  • Using CodeIgniter class library Image upload
  • A summary of optimized writing methods for Codeigniter operation database tables
  • A summary of codeigniter database operation functions
  • How to make the CodeIgniter database cache automatically expire
  • codeigniter Instructions for using the built-in database class
  • How to integrate smarty and adodb in Codeigniter

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1106127.htmlTechArticleCodeIgniter's connection, configuration and usage for the database, codeigniter database This article describes the connection, configuration of CodeIgniter for the database and how to use it. Share it with everyone...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn