DbInspector.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Amf
  17. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /**
  21. * This class implements authentication against XML file with roles for Flex Builder.
  22. *
  23. * @package Zend_Amf
  24. * @subpackage Adobe
  25. * @copyright Copyright (c) 2009 Zend Technologies USA Inc. (http://www.zend.com)
  26. * @license http://framework.zend.com/license/new-bsd New BSD License
  27. */
  28. class Zend_Amf_Adobe_DbInspector
  29. {
  30. /**
  31. * Connect to the database
  32. *
  33. * @param string $dbType Database adapter type for Zend_Db
  34. * @param array|object $dbDescription Adapter-specific connection settings
  35. * @return Zend_Db_Adapter_Abstract
  36. * @see Zend_Db::factory()
  37. */
  38. protected function _connect($dbType, $dbDescription)
  39. {
  40. if(is_object($dbDescription)) {
  41. $dbDescription = get_object_vars($dbDescription);
  42. }
  43. return Zend_Db::factory($dbType, $dbDescription);
  44. }
  45. /**
  46. * Describe database object.
  47. *
  48. * Usage example:
  49. * $inspector->describeTable('Pdo_Mysql',
  50. * array(
  51. * 'host' => '127.0.0.1',
  52. * 'username' => 'webuser',
  53. * 'password' => 'xxxxxxxx',
  54. * 'dbname' => 'test'
  55. * ),
  56. * 'mytable'
  57. * );
  58. *
  59. * @param string $dbType Database adapter type for Zend_Db
  60. * @param array|object $dbDescription Adapter-specific connection settings
  61. * @param string $tableName Table name
  62. * @return array Table description
  63. * @see Zend_Db::describeTable()
  64. * @see Zend_Db::factory()
  65. */
  66. public function describeTable($dbType, $dbDescription, $tableName)
  67. {
  68. $db = $this->_connect($dbType, $dbDescription);
  69. return $db->describeTable($tableName);
  70. }
  71. /**
  72. * Test database connection
  73. *
  74. * @param string $dbType Database adapter type for Zend_Db
  75. * @param array|object $dbDescription Adapter-specific connection settings
  76. * @return bool
  77. * @see Zend_Db::factory()
  78. */
  79. public function connect($dbType, $dbDescription)
  80. {
  81. $db = $this->_connect($dbType, $dbDescription);
  82. $db->listTables();
  83. return true;
  84. }
  85. /**
  86. * Get the list of database tables
  87. *
  88. * @param string $dbType Database adapter type for Zend_Db
  89. * @param array|object $dbDescription Adapter-specific connection settings
  90. * @return array List of the tables
  91. */
  92. public function getTables($dbType, $dbDescription)
  93. {
  94. $db = $this->_connect($dbType, $dbDescription);
  95. return $db->listTables();
  96. }
  97. }