Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-09-2007, 05:03 PM
Junior Member
 
Join Date: Mar 2007
Posts: 4
Question Results Column Case Changed

When I am selected values from MSSQl, the returned result set has changed the case of my column names:

$sql_ids = "SELECT CID FROM Customers";
$result_ids = $this->remote_db->query($sql_ids);

foreach($result_ids as $row_id){
print_r($row_id);
}

Results in:

Array ( [cid] => 1 ) ;

CID has changed to 'cid' which caused Undefined index errors.

Know anything about this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-09-2007, 07:37 PM
Cristian's Avatar
Administrator
 
Join Date: Feb 2007
Location: Sibiu, Romania
Posts: 99
Default

Hi,

I can't remember exactly now but you must to set:

$this->_connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); //or CASE_DEFAULT

Check a bit if works, and come with a result.

You can use also something similar with:

$params = array ('host' => '127.0.0.1',
'username' => 'user',
'password' => 'pass',
'dbname' => 'mydb',
'transform' => Zend_Db::CASE_DEFAULT);

$db = Zend_Db::factory('PDO_MSSQL', $params);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-12-2007, 03:47 PM
Junior Member
 
Join Date: Mar 2007
Posts: 4
Smile Extended db class to support column case

Going off your suggestion I was able to find this post:
Nabble - How to specify Charset with PDO/MySQL

Which led me to extend the Zend Mssql class as the example showed:

class X_Db_Adapter_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Mssql {
protected function _connect() {
if ($this->_connection)
return;

parent::_connect();

// please do not touch names if I don't tell you to do so
$this->_connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);

}
}

The only downside is that I have to manually include more files since I can't use the factory.
require_once("Zend/Db/Adapter/Pdo/Mssql.php");
require_once("Zend/Db/Adapter/Pdo/X_Mssql.php");

And then create my connection like so:
$db = new X_Db_Adapter_Pdo_Mssql($db_params);

But after doing so my columns are coming back in the original case.

I was not able to find a way to pass the attribute changes through the config or factory.

Thanks!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-12-2007, 04:11 PM
Cristian's Avatar
Administrator
 
Join Date: Feb 2007
Location: Sibiu, Romania
Posts: 99
Default

Am pretty sure you don't need to create new Adapter, but rather set that attribute somehow...

I made same thing sometime ago, just found the code:

$mssql_db[$i] = Zend_Db::factory('PDO_MSSQL', $sites[$i]["mssql_database"]);

$mssql_db[$i]->quote("a"); // is possible to not be needed anymore

$conn = $mssql_db[$i]->getConnection();

if($conn == NULL)
throw new Zend_DB_Adapter_Exception('Connection failed');

$conn->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:38 AM.