Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter doesn't work with an MS Access database
#1

Hi,
 
I'm new to PHP and CodeIgniter and I'm having troubles with the sample application in the Tutorial chapter of the CodeIgniter manual.
It doesn't work with an MS Access database. I managed to connect to it, but exactely the statements for selecting and inserting records into it (in the News_model.php) don't work.

The database connection settings are like:
PHP Code:
$db['default'] = array(
    
'dsn' => 'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=C:\Users\Dinu\Desktop\TestDB.accdb',
    
'hostname' => 'localhost',
    
'username' => 'Dinu',
    
'password' => '',
    
'database' => '',
    
'dbdriver' => 'odbc',
 
    ...
); 

My News_model.php is this:
PHP Code:
<?php
class News_model extends CI_Model {

 
   public function __construct()
 
   {
 
       $this->load->database();
 
   }

 
   public function get_news($slug FALSE)
 
   {
 
       if ($slug === FALSE)
 
       {
 
          // $query = $this->db->get('news');
 
               // Err: Call to undefined method CI_DB_odbc_driver::get()
 
          $query $this->db->query('SELECT * FROM news');
 
               // This is good
 
          
           
return $query->result_array();
 
       }

 
       // $query = $this->db->get_where('news', array('slug' => $slug));
 
           // Err: Call to undefined method CI_DB_odbc_driver::get_where()
 
       // $query = $this->db->query('SELECT * FROM news WHERE slug = "' . $slug . '"');
 
           // Err: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1
 
       $query $this->db->query('SELECT * FROM news', array('slug' => $slug));
 
           // This allways gets only the first news, regardless of what the slug is.

 
       return $query->row_array();
 
   }

 
   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,
 
           'tecst' => $this->input->post('tecst')
 
       );
 
       
        
// return $this->db->insert('news', $data);
 
           // Err: Call to undefined method CI_DB_odbc_driver::insert()
 
       // return $this->db->query('INSERT INTO news (title, slug, tecst) VALUES ("' .
 
                               // $this->input->post('title') . '", "' .
 
                               // $slug . '", "' .
 
                               // $this->input->post('tecst') . '")');
 
           // Err: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3
 
       return $this->db->query('INSERT INTO news (title, slug, tecst) VALUES (s, s, s);'$data);
 
           // Err: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1
 
   }


And the database is attached.
Reply


Messages In This Thread
CodeIgniter doesn't work with an MS Access database - by idNewbee - 08-28-2016, 06:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB