DbInspector.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: DbInspector.php 2504 2011-12-28 07:35:29Z liu21st $
  20. */
  21. /**
  22. * This class implements authentication against XML file with roles for Flex Builder.
  23. *
  24. * @package Zend_Amf
  25. * @subpackage Adobe
  26. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. class Zend_Amf_Adobe_DbInspector
  30. {
  31. /**
  32. * Connect to the database
  33. *
  34. * @param string $dbType Database adapter type for Zend_Db
  35. * @param array|object $dbDescription Adapter-specific connection settings
  36. * @return Zend_Db_Adapter_Abstract
  37. * @see Zend_Db::factory()
  38. */
  39. protected function _connect($dbType, $dbDescription)
  40. {
  41. if(is_object($dbDescription)) {
  42. $dbDescription = get_object_vars($dbDescription);
  43. }
  44. return Zend_Db::factory($dbType, $dbDescription);
  45. }
  46. /**
  47. * Describe database object.
  48. *
  49. * Usage example:
  50. * $inspector->describeTable('Pdo_Mysql',
  51. * array(
  52. * 'host' => '127.0.0.1',
  53. * 'username' => 'webuser',
  54. * 'password' => 'xxxxxxxx',
  55. * 'dbname' => 'test'
  56. * ),
  57. * 'mytable'
  58. * );
  59. *
  60. * @param string $dbType Database adapter type for Zend_Db
  61. * @param array|object $dbDescription Adapter-specific connection settings
  62. * @param string $tableName Table name
  63. * @return array Table description
  64. * @see Zend_Db::describeTable()
  65. * @see Zend_Db::factory()
  66. */
  67. public function describeTable($dbType, $dbDescription, $tableName)
  68. {
  69. $db = $this->_connect($dbType, $dbDescription);
  70. return $db->describeTable($tableName);
  71. }
  72. /**
  73. * Test database connection
  74. *
  75. * @param string $dbType Database adapter type for Zend_Db
  76. * @param array|object $dbDescription Adapter-specific connection settings
  77. * @return bool
  78. * @see Zend_Db::factory()
  79. */
  80. public function connect($dbType, $dbDescription)
  81. {
  82. $db = $this->_connect($dbType, $dbDescription);
  83. $db->listTables();
  84. return true;
  85. }
  86. /**
  87. * Get the list of database tables
  88. *
  89. * @param string $dbType Database adapter type for Zend_Db
  90. * @param array|object $dbDescription Adapter-specific connection settings
  91. * @return array List of the tables
  92. */
  93. public function getTables($dbType, $dbDescription)
  94. {
  95. $db = $this->_connect($dbType, $dbDescription);
  96. return $db->listTables();
  97. }
  98. }