我已经在常规MAMP堆栈上安装了ci,我正在使用this tutorial。但是,我只浏览了Created部分,目前我收到了No database selected错误。
型号:
<?php
class submit_model extends Model {
function submitForm($school, $district) {
$data = array(
'school' => $school,
'district' => $district
);
$this->db->insert('your_stats', $data);
}
}
查看:
<?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(); ?>
控制器:
<?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";
那么,它怎么会给我这个错误信息?
A Database Error Occurred
Error Number: 1046
No database selected
INSERT INTO `your_stats` (`school`, `district`) VALUES ('TJHSST', 'FairFax')
答案 0 :(得分:0)
尝试将密码留空。
我认为这是WAMP和XAMPP的默认值。它也适用于MAMP。
答案 1 :(得分:0)
我假设您(自动)加载数据库类?
仔细检查这个,并检查数据库名称是否正确。