CodeIgniter CodeIgniter Database _php tutorial for database connection, configuration, and usage

Source: Internet
Author: User
Tags getting started with php php framework codeigniter

CodeIgniter for database connection, configuration and usage, CodeIgniter database


This paper describes the connection, configuration and usage of CodeIgniter for database. Share to everyone for your reference, as follows:

1. Database:

Create Database Test;create table users (id int not null,name varchar), pwd varchar ($), email varchar) INSERT INTO use RS values (1, ' shunping ', ' shunping ', ' aa@163.com '); INSERT into users values (2, ' shunping2 ', ' shunping2 ', ' bb@163.com ');

2. I'm using a postgreql.

To configure database parameters in the \codeigniter\system\application\config\database.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";

Test the file db1.php content in the \codeigniter\system\application\controllers directory as follows:

<?phpclass DB1 extends controller{  function index () {    $this->load->database ();    $query = $this->db->query ("Select Name,pwd,email from Users");    foreach ($query->result () as $row) {//returns an array of objects      echo $row->name;      echo $row->pwd;      echo $row->email. "
"; } echo "Total result==". $query->num_rows (); }}? >

Open the browser-typed address:

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

OK, fix it!

I think we must have encountered the problem of not even the database, I spent a lot of energy to solve this problem, now tell you, I hope to learn codeigniter this excellent PHP framework to help you.

More readers interested in PHP related content can view this site topic: "CodeIgniter Introductory Tutorial", "CI (codeigniter) Framework Advanced Tutorial", "PHP date and Time usage summary", "PHP object-oriented Programming introduction tutorial", "PHP string ( String) Usage summary, "Getting Started with Php+mysql database operation" and "PHP common database Operation Skills Summary"

Articles you may be interested in:

    • Using Smarty3 basic configuration in CodeIgniter
    • Analysis of Third_party usage of CodeIgniter Auxiliary third-party class library
    • Design defects and solutions of transaction processing for CodeIgniter framework database
    • Database configuration using CodeIgniter under the Sina SAE cloud Platform
    • CodeIgniter Integration Tank AUTH Permission class library detailed
    • Uploading images using CodeIgniter's class library
    • Summary of optimization of CodeIgniter Operation database table
    • CodeIgniter Database Operation Function Summary
    • How to make the CodeIgniter database cache automatic Expiration processing
    • CodeIgniter How to use the database class
    • Methods of integrating Smarty and ADODB in CodeIgniter

http://www.bkjia.com/PHPjc/1106127.html www.bkjia.com true http://www.bkjia.com/PHPjc/1106127.html techarticle CodeIgniter the connection, configuration and usage of database, CodeIgniter database The connection, configuration and usage of CodeIgniter database are described in this paper. To share with you ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.