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