Welcome Guest, Not a member yet? Register   Sign In
Help with database connection
#1

[eluser]manton[/eluser]
Dear All
Please help me with the database connection. I decided to use CI, but it seems more difficult for me than connecting manually with pure PHP.
I already set up the database config in the database like this
Code:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "pass";
$db['default']['database'] = "products";
$db['default']['dbdriver'] = "mysql";

I have one table called products, and I made a model for that table here's the code:
Code:
<?php
class MProducts extends Model {

    function MProducts()
    {
        parent::Model();
    }
}

function getAllProducts(){
    $data = array();
    $Q = $this->db->get('products');
    if ($Q->num_rows() > 0){
        foreach ($Q->result_array() as $row){
            $data[] = $row;
        }
    }
    $Q->free_result();
    return $data;
    }
and I put it MProducts and also database library in autoload.php and then I have a welcome controller here's the code:
Code:
<?php

class Welcome extends Controller {

    public function __construct()
    {
        parent::Controller();    
    }
    
    function index(){
        $data['title'] = "Welcome to My Shop";
        $data['navlist'] = $this->MProducts->getAllProducts(); [color=red]//line 12[/color]
        $this->load->vars($data);
        $this->load->view('template');
    }
When I run them with the view template I get an error like this:
Fatal error: Call to undefined method MProducts::getAllProducts() in C:\xampp\htdocs\testci\system\application\controllers\welcome.php on line 12
I've been around this problem for 2 days, and wondering what's wrong with my code now I decided I need help. Please help


Messages In This Thread
Help with database connection - by El Forum - 12-07-2008, 08:02 AM
Help with database connection - by El Forum - 12-07-2008, 08:09 AM
Help with database connection - by El Forum - 12-07-2008, 10:03 AM
Help with database connection - by El Forum - 12-07-2008, 10:17 AM
Help with database connection - by El Forum - 12-07-2008, 11:08 AM
Help with database connection - by El Forum - 12-07-2008, 11:11 AM
Help with database connection - by El Forum - 12-07-2008, 11:53 AM
Help with database connection - by El Forum - 12-07-2008, 12:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB