Guest User

Untitled

a guest
Aug 5th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. What is the best way to protect my DB class from being hacked [closed]
  2. class dbinterface {
  3.  
  4. private $_dbLink;
  5. private $dbHost = 'host';
  6. private $dbUser = 'user';
  7. private $dbName = 'name';
  8. private $dbPass = 'pass';
  9. private $dbUserTable = 'table';
  10.  
  11. public function connect ()
  12. {
  13. $this->_dbLink = mysql_connect($this->_dbHost, $this->_dbUser, $this->_dbPass);
  14. if(!$this->_dbLink)
  15. throw new Exception ("Could not connect to database. " . mysql_error());
  16. }
  17.  
  18. function registerUser($userName, $userPassword) {
  19.  
  20. $db = new db();
  21. $db->connect();
  22.  
  23. // Select database
  24. mysql_select_db($this->dbName);
  25.  
  26. $query = "insert into usersExample values (NULL, "$userName", "$userPassword")";
  27. $result = mysql_query($query);
  28.  
  29. // Test to make sure query worked
  30. if(!$result) die("Query didn't work. " . mysql_error());
  31.  
  32. // Get the user ID
  33. $this->userID = mysql_insert_id();
  34.  
  35. // Close database connection
  36. mysql_close($dbLink);
  37.  
  38. } // End registerUser()
  39.  
  40. <?php defined('IN_APP') or die('No access allowed.');
  41.  
  42. define('IN_APP', true);
Add Comment
Please, Sign In to add comment