No database selected error in CodeIgniter running on MAMP stack

Posted by Apophenia Overload on Pro Webmasters See other posts from Pro Webmasters or by Apophenia Overload
Published on 2011-01-02T08:39:36Z Indexed on 2011/01/02 8:58 UTC
Read the original article Hit count: 544

Filed under:
|
|
|

First off, does anyone know of a good place to get help with CodeIgniter? The official community forums are somewhat disappointing in terms of getting many responses.

I have ci installed on a regular MAMP stack, and I’m working on this tutorial. However, I have only gone through the Created section, and currently I am getting a No database selected error.

Model:

<?php 
class submit_model extends Model {

    function submitForm($school, $district) {
        $data = array(
            'school' => $school,
            'district' => $district
        );

        $this->db->insert('your_stats', $data);
    }

} 

View:

<?php $this->load->helper('form'); ?>

<?php echo form_open('main'); ?>

    <p>
        <?php echo form_input('school'); ?>
    </p>

    <p>
        <?php echo form_input('district'); ?>
    </p>

    <p>
        <?php echo form_submit('submit', 'Submit'); ?>
    </p>

<?php echo form_close(); ?> 

Controller:

<?php
class Main extends controller {

    function index() {

        // Check if form is submitted
        if ($this->input->post('submit')) {
            $school = $this->input->xss_clean($this->input->post('school'));
            $district = $this->input->xss_clean($this->input->post('district'));

            $this->load->model('submit_model');
            // Add the post
            $this->submit_model->submitForm($school, $district);
        }
        $this->load->view('main_view');
    }
} 

database.php

$db['default']['hostname'] = "localhost:8889";
$db['default']['username'] = "root";
$db['default']['password'] = "root";
$db['default']['database'] = "stats_test";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci"; 

config.php

$config['base_url']    = "http://localhost:8888/ci/";
...
$config['index_page'] = "index.php";
...
$config['uri_protocol']    = "AUTO"; 

So, how come it’s giving me this error message?

A Database Error Occurred
Error Number: 1046

No database selected

INSERT INTO `your_stats` (`school`, `district`) VALUES ('TJHSST', 'FairFax') 

Is there any way for me to test if CodeIgniter can actually detect the mySQL databases I've created with phpMyAdmin in my MAMP stack?

© Pro Webmasters or respective owner

Related posts about mysql

Related posts about database