|
|||
|
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? |
|
||||
|
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);
__________________
Zend Framework Tutorials | Zend Framework Forums | Zend Framework IRC Channel | | Zend Framework Resources | CoreShifter | Microsoft Forums | Microsoft Links | Microsoft Books |
|
|||
|
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!! |
|
||||
|
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);
__________________
Zend Framework Tutorials | Zend Framework Forums | Zend Framework IRC Channel | | Zend Framework Resources | CoreShifter | Microsoft Forums | Microsoft Links | Microsoft Books |
![]() |
| Thread Tools | |
| Display Modes | |
|
|