[eluser]getSurreal[/eluser]
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.
Code:
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 php.net 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
Code:
$this->load->database('mssqldb');
$this->db->query('select * from mytable');
foreach ($query->result() as $row)
{
echo $row->Hosts;
}
with this error
Code:
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
Code:
$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.
Code:
$sqlconnect=mssql_connect('myserver:931', 'myuser', 'mypass');
$sqldb=mssql_select_db('mydatabase',$sqlconnect);
$sqlquery="SELECT * from mytable;";
$result= mssql_query($sqlquery);
while ($row=mssql_fetch_array($result)) {
echo $row['Hosts'];
}