我在常规MAMP堆栈上安装了ci,并且正在使用this tutorial。但是,我只经历了Created部分,当前出现No No selected 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')
最佳答案
尝试将密码留空。
我认为这是WAMP和XAMPP的默认设置。也可能适用于MAMP。
关于mysql - 在MAMP堆栈上运行的CodeIgniter中没有数据库选择错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4573806/