Search code examples
phpcodeigniter-2

connect to access codeigniter then export to mysql


whats wrong with this code, keep getting "Unable to connect to your database server using the provided settings." when trying to connect with access database

public function update_dbx(){
    $loc='Driver={Microsoft Access Driver (*.mdb)};DBQ='.base_url('database\simardi.mdb');
  $confd['hostname'] = $loc;
  $confd['username'] = '';
  $confd['password'] = '';
  $confd['database'] = $loc;
  $confd['dbdriver'] = 'odbc';
  $confd['dbprefix'] = '';
  $confd['pconnect'] = TRUE;
  $confd['db_debug'] = TRUE;
  $confd['cache_on'] = FALSE;
  $confd['cachedir'] = '';
  $confd['char_set'] = 'utf8';
  $confd['dbcollat'] = 'utf8_general_ci';
  $confd['swap_pre'] = '';
  $confd['autoinit'] = TRUE;
  $confd['stricton'] = FALSE;

    $CI = &get_instance();
    $this->db2 = $CI->load->database('db2', $confd);
    $qryx = $this->db2->query("SELECT * FROM INAKTIFMASTER");
    foreach($qryx->result() as $data){
        $this->db->insert('INAKTIFMASTER',$data);
        //print_r($data);
    }

im trying to export mysql db from accces via upload

i have default and "db2" database config in my database.php

edit

  $db['db2']['hostname'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\xampp\htdocs\site\database\data.mdb';
   $db['db2']['username'] = '';
   $db['db2']['password'] = '';
   $db['db2']['database'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\xampp\htdocs\site\database\data.mdb';

$db['db2']['dbdriver'] = 'odbc';

i need those work with base_url


Solution

  • First of all you are using base_url(). And this is not equal to;

    C:\xampp\htdocs\site\
    

    For access on Directory you can use

    __DIR__."database/data.mdb"
    

    Before executing use var_dump(__DIR__); and check what are you getting.