CodeIgniter Forums
odbc connection to a remote system - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: odbc connection to a remote system (/showthread.php?tid=14179)

Pages: 1 2


odbc connection to a remote system - El Forum - 12-21-2008

[eluser]Waiel[/eluser]
Hi,

i have a project I'm working on it which requires accessing multiple DB on different servers
the Database are Microsoft Access Database.

so i followed the user guide http://ellislab.com/codeigniter/user-guide/database/connecting.html

but i was unable to successfully connect. does the ODBC uses a special port ?

Please note the web server is a Unix based system while the Database servers are all windows


Thanks


odbc connection to a remote system - El Forum - 12-22-2008

[eluser]Waiel[/eluser]
Ok here is an update

i used a program called odbc bridge which allowed the odbc to be available over the network on a specific port as i need

when i do a "telnet dbserver port " i connects so it's available
in my example the server ip is 192.168.1.3 and the port i set is 8888
so telnet 192.168.1.3 8888 will establish a connection

Now in CI it doesn't run any query nor display anything it just shows a blank page ...
here is the configuration i used


Code:
$dbs['hostname'] = '192.168.1.3';
        $dbs['username'] = '';
        $dbs['password'] = '';
        $dbs['database'] = 'qwin_5501q';
        $dbs['dbdriver'] = 'odbc';
        $dbs['dbprefix'] = '';
        $dbs['pconnect'] = True;
        $dbs['db_debug'] = FALSE;
        $dbs['cache_on'] = FALSE;
        $dbs['cachedir'] = "";
        $dbs['char_set'] = "utf8";
        $dbs['dbcollat'] = "utf8_general_ci";
        $dbs['port']= 8888;
        $msdb=$this->load->database($dbs,TRUE);
        
        $mr = $msdb->query("select * from STAFINFO");
        foreach ($mr->result() as $row ){
        
            echo $row->Name;
            echo "<br />";
        }


so anyone have any idea what i'm doing wrong ?


odbc connection to a remote system - El Forum - 12-22-2008

[eluser]Henry Weismann[/eluser]
Are you setting those settings in the database.php config file? Also where is the query and for each?


odbc connection to a remote system - El Forum - 12-22-2008

[eluser]Waiel[/eluser]
No i'm setting this inside the controller
as i'm going to have to connect to multiple servers at the same time

the main database is Mysql set in the database.php

here is the full controler file user.php

Code:
class Users extends Controller {

    function Users()
    {
        parent::Controller();    
    }
    
    function index()
    {

                $dbs['hostname'] = '192.168.1.3';
                $dbs['username'] = '';
                $dbs['password'] = '';
                $dbs['database'] = 'qwin_5501q';
                $dbs['dbdriver'] = 'odbc';
                $dbs['dbprefix'] = '';
                $dbs['pconnect'] = True;
                $dbs['db_debug'] = FALSE;
                $dbs['cache_on'] = FALSE;
                $dbs['cachedir'] = "";
                $dbs['char_set'] = "utf8";
                $dbs['dbcollat'] = "utf8_general_ci";
                $dbs['port']= 8888;
                $msdb=$this->load->database($dbs,TRUE);
        
                $mr = $msdb->query("select * from STAFINFO");
                foreach ($mr->result() as $row ){
        
                    echo $row->Name;
                    echo "<br />";
                }
        }
}

it's just a test to see if it's going to connect


odbc connection to a remote system - El Forum - 12-22-2008

[eluser]Henry Weismann[/eluser]
I am assuming your database either does not have a username or password or you left it out in your post for security reasons.

Try:
Code:
$db['access']['hostname'] = '192.168.1.3';
        $db['access']['username'] = '';
        $db['access']['password'] = '';
        $db['access']['database'] = 'qwin_5501q';
        $db['access']['dbdriver'] = 'odbc';
        $db['access']['dbprefix'] = '';
        $db['access']['pconnect'] = True;
        $db['access']['db_debug'] = FALSE;
        $db['access']['cache_on'] = FALSE;
        $db['access']['cachedir'] = "";
        $db['access']['char_set'] = "utf8";
        $db['access']['dbcollat'] = "utf8_general_ci";
        $db['access']['port']= 8888;
        $msdb=$this->load->database('access',TRUE);
echo "Database Resource: ".$msdb."<br />";
$mr = $msdb->query("select * from STAFINFO");
$result = $mr->result_array()
echo "Database Result as Array: ".print_r($result);



odbc connection to a remote system - El Forum - 12-22-2008

[eluser]Waiel[/eluser]
Thanks Henry
but it give the error
Code:
An Error Was Encountered

You have specified an invalid database connection group.



odbc connection to a remote system - El Forum - 12-22-2008

[eluser]Henry Weismann[/eluser]
Thats wierd...did you change the db config array like so:

Code:
$db['access']['hostname'] = '192.168.1.3';
        $db['access']['username'] = '';
        $db['access']['password'] = '';
        $db['access']['database'] = 'qwin_5501q';
        $db['access']['dbdriver'] = 'odbc';
        $db['access']['dbprefix'] = '';
        $db['access']['pconnect'] = True;
        $db['access']['db_debug'] = FALSE;
        $db['access']['cache_on'] = FALSE;
        $db['access']['cachedir'] = "";
        $db['access']['char_set'] = "utf8";
        $db['access']['dbcollat'] = "utf8_general_ci";
        $db['access']['port']= 8888;
The array is now named db not dbs and it is multidimensional. If you did it does not matter because the way you did it by passing the config parameters is fine. Just try this after you connect:
Code:
echo "Database Resource: ".$msdb."<br />";
$mr = $msdb->query("select * from STAFINFO");
$result = $mr->result_array()
echo "Database Result as Array: ".print_r($result);



odbc connection to a remote system - El Forum - 12-22-2008

[eluser]Waiel[/eluser]
it was my mistake
i added the configuration in the controller

i added to the database.php and tried it

it give me the same result as before

blank page ..
and no connection was made to the server !


odbc connection to a remote system - El Forum - 12-22-2008

[eluser]Henry Weismann[/eluser]
Try making the port a string.


odbc connection to a remote system - El Forum - 12-22-2008

[eluser]Waiel[/eluser]
Still no luck ..

this is driving me crazy ><