Welcome Guest, Not a member yet? Register   Sign In
Error 1046, No database selected, ci running in MAMP
#1

[eluser]Apocryphon[/eluser]
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:
Code:
<?php
class submit_model extends Model {
    
    function submitForm($school, $district) {
        $data = array(
            'school' => $school,
            'district' => $district
        );

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

}

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

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

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

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

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

&lt;?php echo form_close(); ?&gt;

Controller:
Code:
&lt;?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
Code:
$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
Code:
$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?

Code:
A Database Error Occurred
Error Number: 1046

No database selected

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

[eluser]InsiteFX[/eluser]
Not sure with MAMP, but with XAMPP you do not need the port number
:8889 on base_url and database hostname.

Try removing the port number.

InsiteFX
#3

[eluser]Apocryphon[/eluser]
Sorry, that doesn't work. The 8888 is required.
#4

[eluser]InsiteFX[/eluser]
Ok!, was not sure, is the hostname port 8889 or should it also be 8888 ?
Also did you create the database stats_test ?

CI will look for the stats_test database and return the error if it can
not find it!

InsiteFX
#5

[eluser]Apocryphon[/eluser]
Okay, so I've tried it so that in database.php the default db hostname is localhost:8889";

And in config.php I have the baseurl set to "http://localhost:8889/ci/";

I tried it and a file containing this error was created: Got packets out of order

What now?
#6

[eluser]InsiteFX[/eluser]
You still did not say if you created the database stats_test

CodeIgniter will not run without errors until you create the
database.

InsiteFX
#7

[eluser]Apocryphon[/eluser]
I've already created stats_test in phpMyAdmin on my MAMP stack, though.
#8

[eluser]InsiteFX[/eluser]
Ok, this maybe what your looking for not sure!

port - The database port number. Currently only used with the Postgres driver. To use this value you have to add a line to the database config array.

Code:
$db['default']['port'] = 5432;

CodeIgniter User Guide - Database Configuration

Why do you need to include a port number?

InsiteFX
#9

[eluser]Apocryphon[/eluser]
Okay, different track of action: what simple thing can I do to make sure that CodeIgniter can read from my databases in MAMP?




Theme © iAndrew 2016 - Forum software by © MyBB