mssql connection works procedurally but not with database class

I'm able to successfully connect procedurally to my MS SQL database, but when I try to use the database class I have problems.

The first thing I noticed is that mssql.php is coded incorrectly to use port which was recently added for mssql.
function db_connect()
        if ($this->port != '')
            $this->hostname .= ','.$this->port;
This code places a comma between hostname and port number, but the proper syntax from documentation is hostname:port

After I updated mssql.php with that change I no longer got the error about being unable to connect to my database. But I'm still getting an error that I can't resolve.

This code fails
        $this->db->query('select * from mytable');
        foreach ($query->result() as $row)
           echo $row->Hosts;

with this error
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: query

Filename: report/report.php

Line Number: 8

Fatal error: Call to a member function result() on a non-object in /home/vmr/public_html/system/application/controllers/report/report.php on line 8

here are my settings in database.php

$db['mssqldb']['hostname'] = "myserver";
$db['mssqldb']['username'] = "myuser";
$db['mssqldb']['password'] = "mypass";
$db['mssqldb']['database'] = "mydatabse";
$db['mssqldb']['dbdriver'] = "mssql";
$db['mssqldb']['dbprefix'] = "";
$db['mssqldb']['pconnect'] = TRUE;
$db['mssqldb']['db_debug'] = TRUE;
$db['mssqldb']['cache_on'] = FALSE;
$db['mssqldb']['cachedir'] = "";
$db['mssqldb']['port'] = 931;

Procedurally I can connect and return data with this code.

$sqlconnect=mssql_connect('myserver:931', 'myuser', 'mypass');
        $sqlquery="SELECT * from mytable;";
        $result= mssql_query($sqlquery);
        while ($row=mssql_fetch_array($result))    {
            echo $row['Hosts'];

Messages In This Thread
mssql connection works procedurally but not with database class - by El Forum - 09-18-2009, 03:56 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.