manage.testcnx.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Tests database connection.
  5. *
  6. * @package vchamilo
  7. * @author Moheissen Fabien (fabien.moheissen@gmail.com)
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
  9. */
  10. // Loading configuration.
  11. require_once __DIR__.'/../../../main/inc/global.inc.php';
  12. api_protect_admin_script();
  13. global $_configuration;
  14. $plugin = VChamiloPlugin::create();
  15. // Retrieve parameters for database connection test.
  16. $dbParams = array();
  17. $dbParams['db_host'] = $_REQUEST['vdbhost'];
  18. $dbParams['db_user'] = $_REQUEST['vdblogin'];
  19. $dbParams['db_password'] = $_REQUEST['vdbpass'];
  20. $dbParams['root_sys'] = api_get_path(SYS_PATH);
  21. $dbParams = array(
  22. 'driver' => 'pdo_mysql',
  23. 'host' => $_REQUEST['vdbhost'],
  24. 'user' => $_REQUEST['vdblogin'],
  25. 'password' => $_REQUEST['vdbpass'],
  26. //'dbname' => isset($_configuration['main_database']) ? $_configuration['main_database'] : '',
  27. // Only relevant for pdo_sqlite, specifies the path to the SQLite database.
  28. //'path' => isset($_configuration['db_path']) ? $_configuration['db_path'] : '',
  29. // Only relevant for pdo_mysql, pdo_pgsql, and pdo_oci/oci8,
  30. //'port' => isset($_configuration['db_port']) ? $_configuration['db_port'] : '',
  31. );
  32. try {
  33. $database = new \Database();
  34. $connection = $database->connect(
  35. $dbParams,
  36. $_configuration['root_sys'],
  37. $_configuration['root_sys'],
  38. true
  39. );
  40. $list = $connection->getSchemaManager()->listDatabases();
  41. echo $plugin->get_lang('connectionok');
  42. } catch (Exception $e) {
  43. echo $plugin->get_lang('badconnection');
  44. die();
  45. }