Welcome Guest, Not a member yet? Register   Sign In
Connecting to a database
#6

[eluser]Adam Liszkai[/eluser]
If you have multiple databases then you must fill out the
/application/config/database.php

Code:
$config['hostname'] = "localhost";
$config['username'] = " YOUR USERNAME FOR DATABASES ";
$config['password'] = " YOUR PASSWORD FOR DATABASES ";
$config['database'] = " YOUR DEFAULT DATABASE NAME ";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = ""; // if you have prefix put it there

Then to access multiple database:

Code:
<?
/**
* @name: Kanban model
* @author: 'Adam Liszkai' <[email protected]>
* @return: Kanban model echo message :D
*/
class Kanban_model extends CI_Model
{
  public function __construct()
  {
    parent::__construct();

    // Load html helper
    $this->load->helper('html');

   /*
    *  Connect to the 'kanban' database, if is not the
    *  default in the /application/config/database.php
    *
    */

    $kanban_db = $this->load->database('kanban', TRUE);
  }

  /*
   * @name: Index function
   * @author: 'Adam Liszkai' <[email protected]>
   * @return: Kanban model echo message :D  
   */
  public function index()
  {
    echo(heading('KANBAAAAAAN! :D', 3)."\n\r");

    $query = $kanban_db->get('kanban_table');
    foreach ($query->result() as $row)
    {
       echo($row->kanban_cell.br(1)."\n\r");
    }

    // @TODO: Some more code! :D
  }
}
?&gt;

But if you have just one database, then i suggest fill out the database informations in /application/config/database.php

Code:
$config['hostname'] = "localhost";
$config['username'] = " YOUR USERNAME FOR DATABASE ";
$config['password'] = " YOUR PASSWORD FOR DATABASE ";
$config['database'] = " YOUR DATABASE NAME ";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = ""; // if you have prefix put it there

then use

Code:
&lt;?
/**
* @name: Kanban model
* @author: 'Adam Liszkai' <[email protected]>
* @return: Kanban model echo message :D
*/
class Kanban_model extends CI_Model
{
  public function __construct()
  {
    parent::__construct();

    // Load html helper
    $this->load->helper('html');

    // Load the database
    $this->load->database();
  }
  
  /*
   * @name: Index function
   * @author: 'Adam Liszkai' <[email protected]>
   * @return: Kanban model echo message :D
   */
  public function index()
  {
    echo(heading('KANBAAAAAAN! :D', 3)."\n\r");  

    $query = $this->db->get('kanban_table');
    foreach ($query->result() as $row)
    {
       echo($row->kanban_cell.br(1)."\n\r");
    }

    // @TODO: Some more code! :D
  }
}
?&gt;

this modell Smile

More examples: http://ellislab.com/codeigniter/user-gui...index.html


Messages In This Thread
Connecting to a database - by El Forum - 07-16-2012, 02:49 AM
Connecting to a database - by El Forum - 07-16-2012, 03:09 AM
Connecting to a database - by El Forum - 07-16-2012, 04:08 AM
Connecting to a database - by El Forum - 07-16-2012, 05:17 AM
Connecting to a database - by El Forum - 07-18-2012, 01:30 AM
Connecting to a database - by El Forum - 07-18-2012, 02:05 AM
Connecting to a database - by El Forum - 07-18-2012, 05:36 AM
Connecting to a database - by El Forum - 07-20-2012, 01:10 AM
Connecting to a database - by El Forum - 11-01-2012, 09:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB