Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 0.8.0
-
Fix Version/s: 0.9.0
-
Component/s: Zend_Db_Table
-
Labels:None
Description
It appears I am unable, using Zend db, to access columns named in camelCaps.
Example:
Table "users" with three columns - "name," "password," and "passwordHash"
--------- code after -------------------
$params = array ('host' => $host,
'username' => $username,
'password' => $password,
'dbname' => $dbname);
$db = Zend_Db::factory('PDO_MYSQL', $params);
// set the default adapter for all Zend_Db_Table objects
require_once 'Zend/Db/Table.php';
Zend_Db_Table::setDefaultAdapter($db);
// connect to a table in the database
class Users extends Zend_Db_Table {}
$table = new Users();
// fetch many records from the table
$rowset = $table->fetchAll();
// display them all
foreach ($rowset as $row) {
// $row is a Zend_Db_Table_Row object
print_r($row);
echo "<p>"
. htmlspecialchars($row->name) . " "
. htmlspecialchars($row->password)
. htmlspecialchars($row->passwordHash)
. ".</p>\n";
}
?>
----------------- end code --------------------
Output is:
the print_r line gives me :
Zend_Db_Table_Row Object ( [_data:protected] => Array ( [id] => 1 [name] => johndoe [password] => johndoespassword [access] => 10 [passwordhash] => 2o34iu23o4iu2oi3u4 ) [_db:protected] => Zend_Db_Adapter_Pdo_Mysql Object ( [_pdoType:protected] => mysql [_config:protected] => Array ( [host] => mysql.xxxxxxxxxxx.org [username] => xxxxxx [password] => xxxxxxx [dbname] => xxxx_xxxxx) [_fetchMode:protected] => 2 [_profiler:protected] => Zend_Db_Profiler Object ( [_queryProfiles:protected] => Array ( ) [_enabled:protected] => [_filterElapsedSecs:protected] => [_filterTypes:protected] => ) [_connection:protected] => PDO Object ( ) ) [_table:protected] => Users Object ( [_db:protected] => Zend_Db_Adapter_Pdo_Mysql Object ( [_pdoType:protected] => mysql [_config:protected] => Array ( [host] => mysql.xxxxxxx.org [username] => xxxxxxxxx[password] => xxxxxxx[dbname] => xxxx_xxxxxx) [_fetchMode:protected] => 2 [_profiler:protected] => Zend_Db_Profiler Object ( [_queryProfiles:protected] => Array ( ) [_enabled:protected] => [_filterElapsedSecs:protected] => [_filterTypes:protected] => ) [_connection:protected] => PDO Object ( ) ) [_name:protected] => users [_cols:protected] => Array ( [id] => id [name] => name [password] => password [access] => access [passwordHash] => passwordhash ) [_primary:protected] => id ) [_info:protected] => Array ( [name] => users [cols] => Array ( [id] => id [name] => name [password] => password [access] => access [passwordHash] => passwordhash ) [primary] => id ) )
Okay, interesting – the camelCapped column, "passwordHash" is being lowercased to "passwordhash" in one array, but case is preserved the array further down.
so, no suprise then, when the call to "htmlspecialchars($row->passwordHash)" gives me a burp:
Fatal error: Uncaught exception 'Zend_Db_Table_Row_Exception' with message 'column 'passwordHash' not in row' in /home/.xxxxxx/xxxxx/xxxxx.xxxxxx.org/Zend/Db/Table/Row.php:98 Stack trace: #0 /home/.xxxxxx/xxxxx/xxxxx.xxxxxx.org/test.php(80): Zend_Db_Table_Row::__get('passwordHash') #1 {main} thrown in /home/.xxxxxx/xxxxx/xxxxx.xxxxxx.org/Zend/Db/Table/Row.php on line 98
So — I ought to be able to clear the exception and get the column value by lowercasing my call - "htmlspecialchars($row->passwordhash)" No?
Yes and no. No exception is thrown, but — neither is a value:
Zend_Db_Table_Row Object ( [_data:protected] => Array ( [id] => 1 [name] => johndoe [password] => johndoespassword [access] => 10 [passwordhash] => 2o34iu23o4iu2oi3u4 ) [_db:protected] => Zend_Db_Adapter_Pdo_Mysql Object ( [_pdoType:protected] => mysql [_config:protected] => Array ( [host] => xxxx.xxxxxxx.org [username] => xxxxxxx[password] => xxxxxxx[dbname] => xxx_xxxxx) [_fetchMode:protected] => 2 [_profiler:protected] => Zend_Db_Profiler Object ( [_queryProfiles:protected] => Array ( ) [_enabled:protected] => [_filterElapsedSecs:protected] => [_filterTypes:protected] => ) [_connection:protected] => PDO Object ( ) ) [_table:protected] => Users Object ( [_db:protected] => Zend_Db_Adapter_Pdo_Mysql Object ( [_pdoType:protected] => mysql [_config:protected] => Array ( [host] => xxx.xxxxxxxx.org [username] => xxxxxxxx[password] => xxxxxxxxx[dbname] => xxxx_xxx) [_fetchMode:protected] => 2 [_profiler:protected] => Zend_Db_Profiler Object ( [_queryProfiles:protected] => Array ( ) [_enabled:protected] => [_filterElapsedSecs:protected] => [_filterTypes:protected] => ) [_connection:protected] => PDO Object ( ) ) [_name:protected] => users [_cols:protected] => Array ( [id] => id [name] => name [password] => password [access] => access [passwordHash] => passwordhash ) [_primary:protected] => id ) [_info:protected] => Array ( [name] => users [cols] => Array ( [id] => id [name] => name [password] => password [access] => access [passwordHash] => passwordhash ) [primary] => id ) ) johndoe johndoespassword. ^^^^^^ (where's htmlspecialchars($row->passwordhash)?
So, what? The column is not accessible under the framework? I'm not really at liberty to change column names to conform to the framework – well, that's not completely honest; I could - but not without requiring man hours of changes elsewhere. Shouldn't the framework permit me to access all columns with mySQL legal names?
Bug, or Operator Error?
Regards
Issue Links
| This issue duplicates: | ||||
| ZF-50 | Name Filter: PDO::CASE_NATURAL lower case column names |
|
|
|
This issue is not exactly a duplicate, but when
ZF-50is solved, this issue will also be solved.ZF-50is solved, this issue will also be solved.