Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using CodeIgniter to add a record into the database.

database.php:

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'test_user';
$db['default']['password'] = 'test_pwd';
$db['default']['database'] = 'test_db';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

insert function in model.php:

public function set_news()
{
    $this->load->helper('url');

    $slug = url_title($this->input->post('title'), 'dash', TRUE);

    $data = array(
        'title' => $this->input->post('title'),
        'slug' => $slug,
        'text' => $this->input->post('text')
    );

    $this->output->enable_profiler(TRUE);
    return $this->db->insert('news', $data);
}

I get this output when set_news() runs:

  DATABASE:  test_db QUERIES: 1  (Hide)
0.0005       INSERT INTO `news` (`title`, `slug`, `text`) VALUES ('come on', 'come-on', 'work')

However, when I view the table in the database, it still has zero rows. Any idea what's going on? Thanks!

share|improve this question
    
turn on debugging see if you get any errors.. –  David Chase Apr 6 '13 at 3:29
    
With $db['default']['dbdriver'] = 'mysqli', I get error: 'Unable to connect to your database server using the provided settings. Filename: core/Loader.php. Line Number: 346'. With $db['default']['dbdriver'] = 'mysql', I get: 'Unable to select the specified database: test_db. Filename: core/Loader.php. Line Number: 346'. I searched those errors before and people suggested turning off debugging. –  lxetuo Apr 6 '13 at 3:34
    
did auto connect not work? is that why you are manually connecting –  David Chase Apr 6 '13 at 4:09
    
Above scenario is actually from CodeIgniter getting started tutorial. However, when I actually go to write my code, I will not need every page to have a db connection so will probably use manual connection as well. –  lxetuo Apr 6 '13 at 14:36

2 Answers 2

The issue ended up being incorrect username/password. Since I'm dealing with a shared environment, I needed to enter another user/pass combination and then it worked correctly.

share|improve this answer

please check your database user permission

and try change

$db['default']['db_debug'] = FALSE;

to

$db['default']['db_debug'] = TRUE;

share|improve this answer
    
Please see my comment above regarding db_debug. –  lxetuo Apr 6 '13 at 3:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.