Guest User

Untitled

a guest
Dec 11th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * Database Class
  5. * Copyright Liam Symonds
  6. * Authored On: 8/05/2011
  7. */
  8.  
  9. class Database {
  10.  
  11. private static $_instance;
  12. public static $string;
  13. private $_username = "dbUser";
  14. private $_password = "dbPassword";
  15. private $_host = "dbHost";
  16. private $_database = "dbDB";
  17. private $_dbConnection;
  18. private $_dbSelection;
  19. private $_selection;
  20. private $_from;
  21. private $_where;
  22. private $_query;
  23.  
  24. public static function Instance()
  25. {
  26.  
  27. if( !isset( self::$_instance ) )
  28. {
  29. self::$_instance = new Database;
  30. }
  31.  
  32. return self::$_instance;
  33.  
  34. }
  35.  
  36. private function __construct()
  37. {
  38.  
  39. $this->_dbConnection = @mysql_connect( $this->_host, $this->_username, $this->_password );
  40. $this->_dbSelection = @mysql_select_db( $this->_database, $this->_dbConnection );
  41.  
  42. }
  43.  
  44. public function select( $string )
  45. {
  46.  
  47. $this->_selection = $string;
  48.  
  49. return $this;
  50.  
  51. }
  52.  
  53. public function from( $string )
  54. {
  55.  
  56. $this->_from = $string;
  57.  
  58. return $this;
  59.  
  60. }
  61.  
  62. public function where( $string )
  63. {
  64.  
  65. $this->_where = $string;
  66.  
  67. return $this;
  68.  
  69. }
  70.  
  71. public function query()
  72. {
  73.  
  74. $this->_query = mysql_query( "SELECT {$this->_selection} FROM {$this->_from} {$this->_where}" );
  75.  
  76. return $this->_query;
  77.  
  78. }
  79.  
  80. public static function escapeString( $string )
  81. {
  82.  
  83. self::$string = mysql_real_escape_string( $string );
  84.  
  85. return self::$string;
  86.  
  87. }
  88.  
  89. }
  90.  
  91. $db = Database::Instance();
  92.  
  93. ?>
Add Comment
Please, Sign In to add comment