peardbAdapter.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * The newest version of the PearDB adapter includes a hack to type number column
  4. * types as numbers, despite the fact that PHP does not offer this kind of info by default
  5. *
  6. * A contribution of Jaybee Reeves
  7. *
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @copyright (c) 2003 amfphp.org
  10. * @package flashservices
  11. * @subpackage adapters
  12. * @version $Id: peardbAdapter.php,v 1.1 2005/07/05 07:56:29 pmineault Exp $
  13. */
  14. require_once(AMFPHP_BASE . "shared/adapters/RecordSetAdapter.php");
  15. class peardbAdapter extends RecordSetAdapter {
  16. /**
  17. * Constructor method for the adapter. This constructor implements the setting of the
  18. * 3 required properties for the object.
  19. *
  20. * @param resource $d The datasource resource
  21. */
  22. function peardbAdapter($d) {
  23. parent::RecordSetAdapter($d);
  24. $fieldcount = $d->numCols();
  25. $intFields = array();
  26. $info = $d->dbh->tableInfo($d);
  27. for($i = 0; $i < $fieldcount; $i++) {
  28. $this->columnNames[$i] = $this->_charsetHandler->transliterate($info[$i]['name']);
  29. $type = $info[$i]['type'];
  30. if(in_array($type, array('int', 'real', 'year')))
  31. {
  32. $intFields[] = $i;
  33. }
  34. }
  35. if($d->numRows() > 0)
  36. {
  37. $line = $d->fetchRow(DB_FETCHMODE_ORDERED, 0);
  38. do {
  39. foreach($intFields as $key => $val)
  40. {
  41. $line[$val] = (float) $line[$val];
  42. }
  43. $this->rows[] = $line;
  44. } while ($line = $d->fetchRow(DB_FETCHMODE_ORDERED, $rows));
  45. }
  46. }
  47. }
  48. ?>