ODBC

#1
[eluser]North2Alaska[/eluser]
I'm setting up a new app that will connect to a MS Sql Server database. When I initialize the database.php file and run the welcome controller, I get the following error:

Code:
Fatal error: Call to undefined method CI_DB::CI_DB() in E:\wamp\www\ci\system\database\drivers\odbc\odbc_driver.php on line 53

I thought maybe ODBC wasn't setup correctly, but I can query the database with direct commands:

Code:
$conn=odbc_connect('Driver={SQL Server Native Client 10.0};Server=zrtpd0j6\Corp1;Database=Pricing;','myuser','thePass');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT 'HELLO WORLD' as msg";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<table><tr><th>Message</th>";
while (odbc_fetch_row($rs))
  {
  $msg=odbc_result($rs,"msg");
  echo "<tr><td>$msg</td></tr>";
  }
odbc_close($conn);
echo "</table>";

My database.php looks like this:
Code:
$db['default']['hostname'] = "Driver={SQL Server Native Client 10.0};Server=zrtpd0j6\Corp1;";
$db['default']['username'] = "myUser";
$db['default']['password'] = "thePass";
$db['default']['database'] = "Pricing";
$db['default']['dbdriver'] = "odbc";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "";
$db['default']['dbcollat'] = "";

I am running on Windows XP with WAMP running locally. I am using the latest SVN version of CI, even though it says 1.7.1.

I've done a search of the forums but find nothing recent about this error. Any suggestions?

#2
[eluser]Unknown[/eluser]
I had the same error. after hours and hours i got it work in the following way:

1. go to the system\database\drivers\odbc\odbc_driver.php and comment out the whole function CI_DB_odbc_driver($params) line 51 to line 56 -> this seems to be a bug in the constructor.

2. do not use statements like (foreach $query->result() as $row){ echo $row->ID;} ... use instead (foreach $query->result_array() as $row){ echo $row['ID'];} this works for me.

3. i don't exactly know if there's another mistake within codeigneter or php with odbc. i can't use $query->num_rows(). this always gives back -1 no matter if there's a record selected or not. i use instead a seperate counter like $count = 0; foreach (....){count++;}

hope i could help you, 'cause i was sitting for about 2 days on that problem but now it works.

Chris

#3
[eluser]jadfreak[/eluser]
[quote author="North2Alaska" date="1252097374"]I'm setting up a new app that will connect to a MS Sql Server database. When I initialize the database.php file and run the welcome controller, I get the following error:

Code:
Fatal error: Call to undefined method CI_DB::CI_DB() in E:\wamp\www\ci\system\database\drivers\odbc\odbc_driver.php on line 53

I thought maybe ODBC wasn't setup correctly, but I can query the database with direct commands:

Code:
$conn=odbc_connect('Driver={SQL Server Native Client 10.0};Server=zrtpd0j6\Corp1;Database=Pricing;','myuser','thePass');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT 'HELLO WORLD' as msg";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<table><tr><th>Message</th>";
while (odbc_fetch_row($rs))
  {
  $msg=odbc_result($rs,"msg");
  echo "<tr><td>$msg</td></tr>";
  }
odbc_close($conn);
echo "</table>";

My database.php looks like this:
Code:
$db['default']['hostname'] = "Driver={SQL Server Native Client 10.0};Server=zrtpd0j6\Corp1;";
$db['default']['username'] = "myUser";
$db['default']['password'] = "thePass";
$db['default']['database'] = "Pricing";
$db['default']['dbdriver'] = "odbc";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "";
$db['default']['dbcollat'] = "";

I am running on Windows XP with WAMP running locally. I am using the latest SVN version of CI, even though it says 1.7.1.

I've done a search of the forums but find nothing recent about this error. Any suggestions?[/quote]


im just confused..
in "Driver={SQL Server Native Client 10.0};Server=zrtpd0j6\Corp1;", what is Corp1?

#4
[eluser]flaky[/eluser]
It's the database instance, mssql has them. First part is the server name, after the "\" it's the instance name

#5
[eluser]sketchynix[/eluser]
[quote author="chrissie1982" date="1255109557"]I had the same error. after hours and hours i got it work in the following way:

1. go to the system\database\drivers\odbc\odbc_driver.php and comment out the whole function CI_DB_odbc_driver($params) line 51 to line 56 -> this seems to be a bug in the constructor.

2. do not use statements like (foreach $query->result() as $row){ echo $row->ID;} ... use instead (foreach $query->result_array() as $row){ echo $row['ID'];} this works for me.

3. i don't exactly know if there's another mistake within codeigneter or php with odbc. i can't use $query->num_rows(). this always gives back -1 no matter if there's a record selected or not. i use instead a seperate counter like $count = 0; foreach (....){count++;}

hope i could help you, 'cause i was sitting for about 2 days on that problem but now it works.

Chris[/quote]

Thanks for figuring this out Chris. I am connecting to an MSSQL instance and was able to get the class to work with this.

I was able to get all the other functions working properly by setting
Code:
var $_random_keyword = ' ASC';

Nick

#6
[eluser]2SG[/eluser]
calling
Code:
parent::CI_DB_driver($params);
in the constructor instead of
Code:
parent::CI_DB($params);
will resolve this issue.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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