CodeIgniter Forums
CodeIgniter doesn't work with an MS Access database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: CodeIgniter doesn't work with an MS Access database (/showthread.php?tid=66043)



CodeIgniter doesn't work with an MS Access database - idNewbee - 08-28-2016

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.


RE: CodeIgniter doesn't work with an MS Access database - Joel Catantan - 08-29-2016

Why MS Access? You can try free download DB like MySQLi. If you want to code PHP without hassle in installation, use XAMPP or WAMP. It has packages of Apache and MySQLi. The CI haven't support for MS Access. Read the Server Requirements of CI http://www.codeigniter.com/user_guide/general/requirements.html.

CHEERS!


RE: CodeIgniter doesn't work with an MS Access database - idNewbee - 08-30-2016

I used Access becouse with it I have some experiance. CI works just fine with MySQL .
I used EasyPHP Devserver becouse it sais it has suport for other languages too Python, Ruby and Perl (I hope there's not just a command line). But becouse EasyPHP Devserver  doesn't have phpMyAdmin, I instaled WAMP too.

MySQL is a lot better then MS Access anyway. And I found that Access has it's own ways of getting to the web.

Thank you Joel.


RE: CodeIgniter doesn't work with an MS Access database - Joel Catantan - 08-30-2016

(08-30-2016, 01:27 AM)idNewbee Wrote: I used Access becouse with it I have some experiance. CI works just fine with MySQL .
I used EasyPHP Devserver becouse it sais it has suport for other languages too Python, Ruby and Perl (I hope there's not just a command line). But becouse EasyPHP Devserver  doesn't have phpMyAdmin, I instaled WAMP too.

MySQL is a lot better then MS Access anyway. And I found that Access has it's own ways of getting to the web.

Thank you Joel.


For learning purpose, I think there is no problem of using MS Access. But if you insist of creating Web App and your DB is MS Access, that's "WOAH! Dude no!" MS Access has so many limitation and disadvantages. You can find these by googling it. 

Just a piece of advice:
Using your experience with specific tool is not a problem but don't limit yourself. Try to explore some other tools! You will find it yourself that there are so many cool stuff available to you.  


Cheers!


RE: CodeIgniter doesn't work with an MS Access database - InsiteFX - 08-30-2016

Do you have an ODBC driver installed on your system?

ODBC Driver


RE: CodeIgniter doesn't work with an MS Access database - idNewbee - 08-30-2016

Cheers!

Quote:For learning purpose, I think there is no problem of using MS Access. But if you insist of creating Web App and your DB is MS Access, that's "WOAH! Dude no!" MS Access has so many limitation and disadvantages. You can find these by googling it.

Just a piece of advice:
Using your experience with specific tool is not a problem but don't limit yourself. Try to explore some other tools! You will find it yourself that there are so many cool stuff available to you.

With Access I got stack becouse I had to make a big application in Office and I learned it on the fly. Office is great, but what I wanted to do is some real programming.

Quote:Do you have an ODBC driver installed on your system?

I just uncommented this line
extension=php_pdo_odbc.dll
in php.ini. But I don't want to go through all that.