PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/vdl-include/vdl-core/core_db.class.php

https://github.com/ivansoriasolis/Vidali
PHP | 66 lines | 36 code | 5 blank | 25 comment | 2 complexity | 8dde0f1e7b98b5b1d59bbb952c74d7c6 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. class CORE_DB{
  3. /**
  4. *
  5. * We start to parse "db.ini" that stores the main info to connect to MySQL server.
  6. */
  7. public function __construct (){
  8. if( !defined('DBDIR')){
  9. $config=parse_ini_file("db.ini",true);
  10. define ("DBDIR",$config["DB"]["DBDIR"]);
  11. define ("DBUSR",$config["DB"]["DBUSR"]);
  12. define ("DBPSW",$config["DB"]["DBPSW"]);
  13. define ("DBASE",$config["DB"]["DBASE"]);
  14. }
  15. }
  16. /**
  17. *
  18. * Destruct.
  19. */
  20. public function __destruct(){
  21. }
  22. /**
  23. *
  24. * We close mysql connection here.
  25. */
  26. public function close($_con){
  27. $_con->close();
  28. }
  29. /**
  30. *
  31. * We start the connection to MySQL server. Return the connection value and also saves in $_connection.
  32. */
  33. public function connect (){
  34. $connection = new mysqli(DBDIR, DBUSR, DBPSW, DBASE);
  35. /* check connection */
  36. if ($connection->connect_errno) {
  37. printf("Connect failed: %s\n", $connection->connect_error);
  38. exit();
  39. }
  40. return $connection;
  41. }
  42. /**
  43. *
  44. * We modify db.ini with the new values given.
  45. * @param $_dbdir: Store new MySQL dir.
  46. * @param $_dbusr: Store new MySQL username.
  47. * @param $_dbpsw: Store new MySQL password.
  48. * @param $_dbase: Store new MySQL database.
  49. */
  50. public function set($_dbdir,$_dbusr,$_dbpsw,$_dbase){
  51. $file = fopen("../vdl-include/vdl-core/db.ini","w");
  52. $string="[DB]\n
  53. DBDIR=$_dbdir\n
  54. DBUSR=$_dbusr\n
  55. DBPSW=$_dbpsw\n
  56. DBASE=$_dbase";
  57. fputs($file,$string);
  58. fclose($file);
  59. }
  60. }
  61. ?>